binary structures

1.0.0

A library for reading, writing, and representing structures from binary representations

About binary-structures

This is yet another library implementing a compiler to make parsing binary files or structures easier. It generates reader and writer functions to translate from streams, octet vectors, and memory pointers directly, and has an extensible protocol to allow implementing other storage backends as well.

How To

The primary entry point is via define-io-structure. It'll define the structure type, io-type, and the parsing functions for you in one go. Here's an example that shows off most capabilities:

(define-io-structure rgb
  (r uint8)
  (g uint8)
  (b uint8))

(define-io-structure rgba
  (:include rgb)
  (a uint8))

(define-io-structure image
  "IMG"
  (version uint8)
  (width uint32)
  (height uint32)
  (pixel-type (case uint8
                (1 'uint8)
                (2 'rgb)
                (3 'rgba)))
  (data (vector (case (slot pixel-type)
                  (uint8 uint8)
                  (rgb rgb)
                  (rgba rgba))
                (* (slot width) (slot height)))))

From there you should have a read-image and write-image function, as well as the image structure and accessors to deal with the data.

Limitations

This library is best suited towards files with a clear, fixed layout that grows sequentially from the beginning. Formats like ZIP that need to be scanned from the end cannot be decoded. There's also no way to restructure data after it has been parsed, so you may need additional wrapper functions or a secondary translation step to create a truly convenient view of the data. Finally, all data must be octet-aligned.

System Information

1.0.0
Nicolas Hafner
zlib

Definition Index