Binary-types is a library for accessing binary format files with fixed bit-length code-words. Binary-types provides macros that are used to declare the mapping between lisp objects and some binary (i.e. octet-based) representation.

Supported kinds of binary types include:

  • Signed and unsigned integers of any octet-size, big-endian or little-endian. Maps to lisp integers.

  • Enumerated types based on any integer type. Maps to lisp symbols.

  • Complex bit-field types based on any integer type. Sub-fields can be numeric, enumerated, or bit-flags. Maps to lisp lists of symbols and integers.

  • Fixed-length and null-terminated strings. Maps to lisp strings.

  • Compound records of other binary types. Maps to lisp DEFCLASS classes or, when you prefer, DEFSTRUCT structs.

Typically, a complete binary record format/type can be specified in a single (nested) declaration statement. Such compound records may then be read and written with READ-BINARY and WRITE-BINARY.

Binary-types is *not* helpful in reading files with variable bit-length code-words, such as most compressed file formats. It will basically only work with file-formats based on 8-bit bytes (octets). Also, at this time no floating-point types are supported out of the box. The ieee-floats library might be useful.

Binary-types was developed by Frode Vatvedt Fjeld. Source code is available at See the Debian page for information on how to get a debian-package of binary-types using common-lisp-controller.

There are some extensions to binary-types in binary-types-extra.lisp at It adds support for structs with "bitfields" and for vectors. There is also a binary-rw-gen.lisp that compiles a binary-type into specialized reader- and writer- functions that are somewhat faster.

There is also a Debian package.