#binary-data #binary-parser #structs #read #macro-derive #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

#449 in Rust patterns

Download history 8347/week @ 2024-01-02 10700/week @ 2024-01-09 11919/week @ 2024-01-16 12436/week @ 2024-01-23 14112/week @ 2024-01-30 19905/week @ 2024-02-06 19915/week @ 2024-02-13 15919/week @ 2024-02-20 13672/week @ 2024-02-27 16066/week @ 2024-03-05 12275/week @ 2024-03-12 14231/week @ 2024-03-19 13754/week @ 2024-03-26 13450/week @ 2024-04-02 12782/week @ 2024-04-09 13526/week @ 2024-04-16

56,700 downloads per month
Used in 214 crates (33 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
~35K SLoC