[cl-store-devel] Serialize to string stream

Sean Ross rosssd at gmail.com
Wed Aug 8 10:11:11 UTC 2007


On 8/8/07, Saurabh Nanda <saurabhnanda at gmail.com> wrote:
> "can't write-byte to a string stream" error.
>
> (with-output-to-string (out)
>            (cl-store:store "abc" out))
>
> What am I doing wrong?

Hi Saurabh,
Currently cl-store only uses write-byte to serialize the values and
string-output-streams do not support stream-write-byte. If you are
sending objects over the wire you can (provided the
stream-element-type is '(unsigned-byte 8)) just
store the value directly into the stream.

If not however ....

Edi Weitz' flexi-streams (http://weitz.de/flexi-streams) package
provides all you need to get this to work.

I would recommend using a flexi-stream:in-memory-output-stream as your output
(and avoid the int => character conversion overhead)
eg.

(flex:with-output-to-sequence (outs)
  (cl-store:store '(1 2 3 4) outs))

but if you particularly want to serialize a value into a string you
can wrap a string-output-stream in a flexi-stream

 eg.
 (with-output-to-string (out)
   (let ((flex (flex:make-flexi-stream out)))
     (cl-store:store '(1 2 3 4) flex)))

cheers,
  sean



More information about the cl-store-devel mailing list