Cloud Parts

Declarative binary layouts

Describe the layout once, on a struct or as a schema object, and the library derives both the reader and the writer from that description.

How they work

In Rust, deku and binrw are derive macros: attributes on a struct say how each field is stored, such as #[deku(bits = 4)] for a 4-bit field, count = "count" for an array whose length came earlier, or binrw’s magic = b"DOG" for fixed leading bytes. Construct does the same in Python by building a Struct object out of pieces like Const, BitStruct and PrefixedArray. Because the description is data rather than parsing code, one definition parses bytes into objects and builds objects back into bytes, so the reader and writer can’t drift apart.

They differ in reach. deku works at bit level throughout. binrw reads whole bytes from any io::Read + io::Seek stream, follows offsets with FilePtr, and leaves bit fields to helper crates. Construct is Python only, though it can compile a definition into faster Python code. Kaitai Struct takes the idea further: its descriptions are YAML files compiled into parsers for many languages, and its FAQ calls Construct its closest analogue.

This style suits formats made of fixed fields, counts and tagged variants. When a field’s meaning depends on more context than attributes can express, each library lets you drop into a hand-written reader function for that one field.

Technologies

What all binary parsing and encoding have in common →

Sources

Improve this page on GitHub