A Go library for decoding binary data into structured Go types using tags, with support for offsets, calculations, and custom methods.
Binstruct is a Go library that simplifies parsing binary data by mapping it directly into Go structs using declarative struct tags. It reduces boilerplate code when working with binary file formats like ZIP and PNG by providing both high-level struct mapping and low-level stream reading capabilities.
Go developers who need to parse or decode binary file formats, network protocols, or any structured binary data, particularly those looking to avoid manual bit-twiddling and repetitive parsing logic.
Developers choose Binstruct for its declarative approach using struct tags, which makes parsing complex binary structures more readable and maintainable than manual byte-by-byte reading. It uniquely combines flexible tag-based mapping with a full-featured binary Reader interface, offering both convenience and low-level control.
Golang binary decoder for mapping data into the structure
Open-Awesome is built by the community, for the community. Submit a project, suggest an awesome list, or help improve the catalog on GitHub.
Maps binary data directly to Go structs using tags, reducing boilerplate as shown in the ZIP and PNG decoder examples, making code more readable and maintainable.
Supports tags for length, offsets, byte order, and field references with calculations, allowing precise control over parsing logic without manual bit-twiddling.
Offers both high-level struct decoding and a low-level Reader interface, providing flexibility for different parsing needs, from quick mappings to direct stream access.
Handles arrays, slices (including multi-dimensional), nested structs, and embedding, enabling parsing of intricate binary formats like those in the test examples.
For types like int, uint, and string, sizes aren't inferred automatically—requiring explicit tags (e.g., `bin:"len:42"`), which can lead to errors if overlooked.
The tag system with calculations, nested references, and offsets can become verbose and hard to debug, especially for deep structures, as noted in the README's tag examples.
As a niche library, it lacks the extensive community support, documentation, and pre-built parsers compared to more established alternatives like encoding/binary.