#binary-parser #binary-data #structs #macro-derive #read #helping #methods

no-std binread

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

11 stable releases

2.2.0 Aug 25, 2021
2.1.1 Apr 1, 2021
2.1.0 Mar 28, 2021
1.4.1 Nov 11, 2020
1.0.2 Jul 15, 2020

#533 in Rust patterns

Download history 12508/week @ 2024-08-02 10418/week @ 2024-08-09 12845/week @ 2024-08-16 13525/week @ 2024-08-23 12834/week @ 2024-08-30 12725/week @ 2024-09-06 10719/week @ 2024-09-13 11166/week @ 2024-09-20 11687/week @ 2024-09-27 11745/week @ 2024-10-04 10392/week @ 2024-10-11 12389/week @ 2024-10-18 12630/week @ 2024-10-25 11158/week @ 2024-11-01 11726/week @ 2024-11-08 13396/week @ 2024-11-15

50,876 downloads per month
Used in 258 crates (34 directly)

MIT license

115KB
2K SLoC

binread

tests docs.rs codecov discord matrix: #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.

#[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<u16>,

    #[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

Dependencies

~1.5MB
~38K SLoC