Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
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✨
- Host: GitHub
- URL: https://github.com/jam1garner/binread
- Owner: jam1garner
- License: mit
- Created: 2020-03-19T19:18:31.000Z (almost 5 years ago)
- Default Branch: master
- Last Pushed: 2023-02-24T06:20:07.000Z (almost 2 years ago)
- Last Synced: 2025-01-03T02:53:58.498Z (5 days ago)
- Language: Rust
- Homepage:
- Size: 379 KB
- Stars: 260
- Watchers: 6
- Forks: 18
- Open Issues: 8
-
Metadata Files:
- Readme: README.md
- License: LICENSE
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/)