From saurabhnanda at gmail.com Wed Aug 8 08:16:02 2007 From: saurabhnanda at gmail.com (Saurabh Nanda) Date: Wed, 8 Aug 2007 13:46:02 +0530 Subject: [cl-store-devel] Serialize to string stream Message-ID: <794f042d0708080116x1a6f155pc1812e40df20c99e@mail.gmail.com> Hi, I'm trying to send an object over the wire between two Lisp images. Right now I have to first serialize, store in file, read file into string, and send using HTTP. Can CL-Store serialize an object and store it to a string stream? I've tried the following but I'm getting "can't write-byte to a string stream" error. (with-output-to-string (out) (cl-store:store "abc" out)) What am I doing wrong? Thanks, Saurabh. -- http://nandz.blogspot.com http://foodieforlife.blogspot.com From rosssd at gmail.com Wed Aug 8 10:11:11 2007 From: rosssd at gmail.com (Sean Ross) Date: Wed, 8 Aug 2007 11:11:11 +0100 Subject: [cl-store-devel] Serialize to string stream In-Reply-To: <794f042d0708080116x1a6f155pc1812e40df20c99e@mail.gmail.com> References: <794f042d0708080116x1a6f155pc1812e40df20c99e@mail.gmail.com> Message-ID: <5bef28df0708080311o3ee51920tf63eaca15e7fc77e@mail.gmail.com> On 8/8/07, Saurabh Nanda 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 From ctdean at sokitomi.com Wed Aug 8 18:26:26 2007 From: ctdean at sokitomi.com (Chris Dean) Date: Wed, 08 Aug 2007 11:26:26 -0700 Subject: [cl-store-devel] Serialize to string stream In-Reply-To: <5bef28df0708080311o3ee51920tf63eaca15e7fc77e@mail.gmail.com> (Sean Ross's message of "Wed, 8 Aug 2007 11:11:11 +0100") References: <794f042d0708080116x1a6f155pc1812e40df20c99e@mail.gmail.com> <5bef28df0708080311o3ee51920tf63eaca15e7fc77e@mail.gmail.com> Message-ID: "Sean Ross" writes: > Edi Weitz' flexi-streams (http://weitz.de/flexi-streams) package > provides all you need to get this to work. That's a great solution, and it's what we used in the past. Here's another solution: we are pushing large amounts of data through cl-store so we wrote some custom stream classes for cl-store to use. Part of our code is below -- it uses LispWorks specific classes so you'll need to make changes if you don't use LispWorks. (to-storage-vector (cons 123 "foo")) => #(67 76 45 83 11 24 0 1 1 24 0 1 123 35 1 3 102 111 111) Cheers, Chris Dean (defclass write-byte-only-stream (fundamental-stream) ((data :accessor data-of :initarg :data :initform nil)) (:documentation "A partial stream that only supports the write-byte function.")) (defun make-write-byte-only-stream () (make-instance 'write-byte-only-stream :data (make-array 16 :fill-pointer 0 :adjustable t :element-type '(unsigned-byte 8)))) (defmethod stream-element-type ((stream write-byte-only-stream)) 'octet) (defmethod stream-write-byte ((stream write-byte-only-stream) byte) "Writes a byte by extending the underlying vector." (vector-push-extend byte (data-of stream) (length (data-of stream))) byte) (defun to-storage-vector (obj) (let ((out (make-write-byte-only-stream))) (cl-store:store obj out) (data-of out)))