Function: bindat-type
bindat-type is a macro defined in bindat.el.gz.
Signature
(bindat-type &rest TYPE)
Documentation
Return the Bindat type value to pack&unpack TYPE.
TYPE is a Bindat type expression. It can take the following forms:
uint BITLEN [LE] - unsigned integer (big-endian if LE is nil)
str LEN - Byte string
strz [LEN] - Zero-terminated byte-string
bits LEN - Bit vector (LEN is counted in bytes)
fill LEN - Just a filler
align LEN - Fill up to the next multiple of LEN bytes
vec COUNT TYPE - COUNT repetitions of TYPE
type EXP - Indirection; EXP should return a Bindat type value
unit EXP - 0-width type holding the value returned by EXP
struct FIELDS... - A composite type
When the context makes it clear, the symbol struct can be omitted.
A composite type is a list of FIELDS where each FIELD is of the form
(LABEL TYPE)
where LABEL can be _ if the field should not deserve a name.
Composite types get normally packed/unpacked to/from alists, but this can be
controlled in the following way:
- If the list of fields ends with :unpack-val EXP, then unpacking will
return the value of EXP (which has the previous fields in its scope).
- If a field's TYPE is followed by :pack-val EXP, then the value placed
into this field will be that returned by EXP instead of looking up the alist.
- If the list of fields is preceded with :pack-var VAR then the object to
be packed is bound to VAR when evaluating the EXPs of :pack-val.
All the above BITLEN, LEN, LE, COUNT, and EXP are Elisp expressions evaluated in the current lexical context extended with the previous fields.
TYPE can additionally be one of the Bindat type macros defined with
bindat-defmacro (and listed below) or an Elisp expression which returns
a bindat type expression.
-- (u8)
Unsigned 8bit integer.
-- (sint BITLEN LE)
Signed integer of size BITLEN. Big-endian if LE is nil and little-endian if not.
-- (uintr BITLEN)
(deprecated since Emacs-29) Little-endian unsigned integer.
-- (repeat COUNT &rest TYPE)
Like vec, but unpacks to a list rather than a vector.
Probably introduced at or before Emacs version 28.1.
Source Code
;; Defined in /usr/src/emacs/lisp/emacs-lisp/bindat.el.gz
(def-edebug-elem-spec 'bindat-type
'(&or ["uint" def-form &optional def-form]
["uintr" def-form]
["str" def-form]
["strz" &optional def-form]
["bits" def-form]
["fill" def-form]
["align" def-form]
["vec" def-form bindat-type]
["repeat" def-form bindat-type]
["type" def-form]
["struct" bindat-struct]
["unit" def-form]
[":pack-var" symbolp bindat-type]
symbolp ;; u8, u16, etc...
bindat-struct))