[cl-store-devel] Serialize to string stream
ctdean at sokitomi.com
Wed Aug 8 18:26:26 UTC 2007
"Sean Ross" <rosssd at gmail.com> 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)
(defclass write-byte-only-stream (fundamental-stream)
((data :accessor data-of :initarg :data :initform nil))
"A partial stream that only supports the write-byte function."))
(defun make-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))
(defmethod stream-write-byte ((stream write-byte-only-stream) byte)
"Writes a byte by extending the underlying vector."
(length (data-of stream)))
(defun to-storage-vector (obj)
(let ((out (make-write-byte-only-stream)))
(cl-store:store obj out)
More information about the cl-store-devel