-
Notifications
You must be signed in to change notification settings - Fork 15
The CUSTOM type
j3pic edited this page Jun 2, 2018
·
4 revisions
(read-binary-type '(custom &key (lisp-type t) reader writer) stream) align element-align)
The CUSTOM
type allows you to explicitly provide code to read and write a datum, and also to optionally declare what Lisp type the resulting value will be.
The reader
is a function that accepts a STREAM argument. It must return two values:
- The fully decoded result of reading from the stream.
- The number of bytes read.
The writer
is a function that accepts the lambda-list (object stream)
, where object
is the object to be written, and stream
is the stream to be written to.
If a custom
type appears in a DEFBINARY
definition and its reader and/or writer are lambda
expressions, then those
lambdas are closures created in a scope where the slots read so far (or all the slots for the writer) are bound to the values that were read or written. You can setf
these bindings, and the changes will be reflected in the struct.