I end up doing something like:

(defmacro with-open-binary-file (args &rest rest)
  `(with-open-file (,@args :element-type '(unsigned-byte 8)) ,@rest))

(defun write-word (word out)
  (write-byte (ldb (byte 8 8) word) out)
  (write-byte (ldb (byte 8 0) word) out))

only because I'm exclusively writing binary stuff to the files this code
serves, and because it parallels the C code that does the same thing
fairly well. I'm not writing to a socket stream, but this may help anyway.
It might need to account for endianness, but I'm not sure. It's been a
while since I've looked at it closely.

Neil Gilmore
ra...@raito.com

> I can't easily verify right now, but check the :external-format on your
> stream: it may be defaulting to UTF-8 and you will need to specify
> something else.
>
>     -tree
>
> Sent from my iPhone
>
>> On Apr 10, 2014, at 10:31, Paul Tarvydas <paultarvy...@gmail.com> wrote:
>>
>> I'm using sbcl to write-char a 16-bit unsigned integer to a socket as
>> two separate unsigned 8-bit bytes, for example 141 should appear as
>>
>> #x00 #x8d.
>>
>> SBCL appears to convert the #x8d into a two-byte utf-8 char, resulting
>> in 3 bytes written to the stream
>>
>> \#x00 #xcd #x8d.
>>
>> What is the proper incantation to achieve this?  (SBCL on Windows, if
>> that matters).
>>
>> thanks
>> pt
>>
>>
>> _______________________________________________
>> pro mailing list
>> pro@common-lisp.net
>> http://common-lisp.net/cgi-bin/mailman/listinfo/pro
>
> _______________________________________________
> pro mailing list
> pro@common-lisp.net
> http://common-lisp.net/cgi-bin/mailman/listinfo/pro
>



_______________________________________________
pro mailing list
pro@common-lisp.net
http://common-lisp.net/cgi-bin/mailman/listinfo/pro

Reply via email to