Why does it say
/* #define CHECK_LSTREAM(x) CHECK_RECORD (x, lstream)
Lstream pointers should never escape to the Lisp level, so
functions should not be doing this. */
in lstream.h? The reason I'm wondering is that I'd like to
make my encode-binary and decode-binary functions work
with arbitrary output sinks/input sources, so the obvious
implementation is to create a suitable Lstream within the
Lisp-visible functions. The trouble is that I want the
interface to the functions to include the facility to add
user-defined conversions, which means that a Lisp function
may have to accept an Lstream parameter... so I'm wondering
whether there was any reason for this comment ;-)
Just in case you're interested, here's the interface I'm
proposing (there'll be an additional encode-binary-string
function that works in an efficient way). The STREAM parameter
could accept any Lisp object for which an Lstream can be
created.
DEFUN ("encode-binary-stream", Fencode_binary_stream, 3, 3, 0, /*
Encode the sequence DATA into a binary STREAM using the specified
binary FORMAT vector. Each element of the FORMAT vector should either
be a symbol, or a list of the form (SYMBOL PARAMETER...). SYMBOL may be
one of
binary string bit-vector integer float space vector
or alternatively the name of a Lisp function that will be called with the
remaining data, the output stream and a list of PARAMETER values as its
arguments. i.e. it's declaration should look something like the following
(defun my-conversion data stream parameter-list ... )
and it will be called using
(my-conversion data stream parameter-list)
Such a function should return the remaining data after it has consumed
whatever it required.
The built-in encodings support the following parameters:
Encoding Parameters
binary :length
string :length :pad :terminator
bit-vector :length :direction
integer :length :signed :direction
float :length :format :direction
space :length
vector FORMAT-ELT :length :pack
where
FORMAT-ELT is anything that could be an element of the FORMAT parameter.
:length is followed by a length in bytes (or in bits for bit-vector).
:pad is followed by a character used to pad the string to the
specified length.
:terminator is followed by a character used to terminate the string.
:direction is followed by one of `big-endian', `little-endian', `host'
or `network'.
:signed is followed by t or nil.
:format is followed by `native'. Conversions to other floating point
formats are currently not supported.
:pack is followed by an integer specifying the vector stride
(e.g. the format [(vector (integer :length 2) :pack 4)]
represents an array of 16-bit integers, but with a gap
of 2 bytes between successive elements).
The function returns a string containing the raw binary data. */
(format, data, stream))
DEFUN ("decode-binary-stream", Fdecode_binary_stream, 2, 2, 0, /*
Decode the specified STREAM using the binary FORMAT vector. See
`encode-binary-stream' for more information on the FORMAT vector;
note however that user-defined conversion functions should be declared
as
(defun my-conversion stream parameter-list ...)
and should return the data they have converted. */
(format, stream))
Kind Regards,
Alastair.
____________________________________________________________
Alastair Houghton ajhoughton(a)lineone.net