Ecosyste.ms: Awesome

An open API service indexing awesome lists of open source software.

Awesome Lists | Featured Topics | Projects

https://github.com/jam1garner/binread

A Rust crate for helping parse structs from binary data using ✨macro magic✨
https://github.com/jam1garner/binread

Last synced: 4 days ago
JSON representation

A Rust crate for helping parse structs from binary data using ✨macro magic✨

Awesome Lists containing this project

README

        

# The binread crate has been superseded by [binrw](https://github.com/jam1garner/binrw), which is the same thing but supports both reads *and* writes! [Upgrade to binrw today!](https://github.com/jam1garner/binrw)

---

# binread

[![tests](https://github.com/jam1garner/binread/actions/workflows/cargo_tests.yml/badge.svg)](https://github.com/jam1garner/binread/actions/workflows/cargo_tests.yml)
[![docs.rs](https://docs.rs/binread/badge.svg)](https://docs.rs/binread)
[![codecov](https://codecov.io/gh/jam1garner/binread/branch/master/graph/badge.svg?token=UREOWI2KAY)](https://codecov.io/gh/jam1garner/binread)
[![discord](https://img.shields.io/discord/818723403871551509?color=gray&label=%20&logo=discord)](https://discord.gg/ABy4Qh549j)
[![matrix: #binrw:matrix.org](https://img.shields.io/badge/style-%23binrw:matrix.org-blue.svg?style=flat&label=[m])](https://matrix.to/#/#binrw:matrix.org)

A Rust crate for helping parse structs from binary data using ✨macro magic✨

## Usage

BinRead uses a derive macro for declaratively defining binary parsing methods for structs.

```rust
#[derive(BinRead)]
#[br(magic = b"DOG", assert(name.len() != 0))]
struct Dog {
bone_pile_count: u8,

#[br(big, count = bone_pile_count)]
bone_piles: Vec,

#[br(align_before = 0xA)]
name: NullString
}

let mut reader = Cursor::new(b"DOG\x02\x00\x01\x00\x12\0\0Rudy\0");
let dog: Dog = reader.read_ne().unwrap();
assert_eq!(dog.bone_piles, &[0x1, 0x12]);
assert_eq!(dog.name.into_string(), "Rudy")
```

[More documentation can be found here](https://docs.rs/binread/)