-
Notifications
You must be signed in to change notification settings - Fork 15
Strings
(read-counted-string size-len stream &key (byte-order :little-endian))
Reads an unsigned integer of size-len
bytes from the stream
in the specified byte-order
,
then reads a byte vector of size-len
bytes. Returns two values:
- The byte vector
- The total number of bytes that were read.
(write-counted-string size-len stream buffer &key (byte-order :little-endian))
Writes the length of the buffer
as an unsigned integer of size-len
bytes in the
specified byte-order
, then writes out the buffer
.
The code generated by DEFBINARY
handles conversion to and from
a normal Lisp string:
(defbinary has-a-counted-string ()
(my-string "" :type (counted-string size-len :external-format :latin1)))
(read-terminated-string stream &key (terminator (buffer 0)))
Reads a string ending in the byte sequence specified by terminator
. The terminator
is
not included in the resulting buffer. The default is to read C-style strings, terminated
by a zero.
(write-terminated-string string stream &key (terminator (buffer 0))
Writes the contents of string
to the stream
, then writes the terminator
.
In DEFBINARY
, the terminator is specified as an integer which must be encoded. The
size of this integer in bytes is required as an additional parameter.
(defbinary has-terminated-string ()
(ends-with-crlf "" :type (terminated-string 2 :terminator #x0d0a) :byte-order :big-endian)
(last-line "" :type (terminated-string 1)))
(defbinary has-a-fixed-length-string ()
(fixed-length "" :type (fixed-length-string 20)))