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 →| binrw | Open source | Open-source project by jam1garner, Colin Snover, Kitlith and roblabla | MIT | 2026-10-09 |
| Construct | Open source | Open-source project by Tomer Filiba, Corbin Simpson and Arkadiusz Bulski | MIT | 2026-10-09 |
| deku | Open source | Open-source project started by Emmanuel Thompson (sharksforarms) | MIT or Apache 2.0 | 2026-10-09 |
Sources
- deku docs on docs.rs: declarative, symmetric, bit-level reading and writing
- binrw docs on docs.rs: directives, io::Read + io::Seek, FilePtr, bit fields via other crates
- Construct docs: Introduction (declarative and symmetrical parser and builder)
- Construct docs: Compilation (faster Python, fewer checks)
- Kaitai Struct FAQ: Construct is the closest analog