To control unpacking and packing, you write a data layout specification, a special nested list describing named and typed fields. This specification controls the length of each field to be processed, and how to pack or unpack it. We normally keep bindat specs in variables whose names end in ‘-bindat-spec’; that kind of name is automatically recognized as risky.
A field's type describes the size (in bytes) of the object
that the field represents and, in the case of multibyte fields, how
the bytes are ordered within the field. The two possible orderings
are big endian (also known as “network byte ordering”) and
little endian. For instance, the number
9165) in big endian would be the two bytes
and in little endian,
#x23. Here are the possible
[127 0 0 1]for localhost.
− 1and ending with zero. For example:
(2 3 4 11 13)and
(3 5 10 11 12).
For a fixed-size field, the length len is given as an integer specifying the number of bytes in the field.
When the length of a field is not fixed, it typically depends on the
value of a preceding field. In this case, the length len can be
given either as a list
...) identifying a
field name in the format specified for
below, or by an expression
) where form
should evaluate to an integer, specifying the field length.
A field specification generally has the form
), where name is optional. Don't use names that
are symbols meaningful as type specifications (above) or handler
specifications (below), since that would be ambiguous. name can
be a symbol or an expression
), in which case
form should evaluate to a symbol.
handler describes how to unpack or pack the field and can be one of the following:
), evaluate expr with the variable
tagdynamically bound to the value of form. A non-
nilresult indicates a match.
equalto the value of form.
evalform is used, it is evaluated just once. For correct operation, each specification in field-specs must include a name.
) forms used in a bindat specification,
the form can access and update these dynamically bound variables
bindat-raw) for unpacking or packing.
bindat-get-fieldto access specific fields of this structure.
repeatblock, these contain the maximum number of repetitions (as specified by the count parameter), and the current repetition number (counting from 0). Setting
countto zero will terminate the inner-most repeat block after the current repetition has completed.