GithubHelp home page GithubHelp logo

swiftb0y / binrw Goto Github PK

View Code? Open in Web Editor NEW

This project forked from jam1garner/binrw

0.0 2.0 0.0 1.06 MB

A Rust crate for helping parse and rebuild binary data using ✨macro magic✨.

License: MIT License

Rust 100.00%

binrw's Introduction

binrw

crates tests docs.rs codecov discord matrix: #binrw:matrix.org

binrw helps you write maintainable & easy-to-read declarative binary data readers and writers using ✨macro magic✨.

Features

  • Generates efficient data parsers and serialisers for structs and enums using #[derive]
  • Reads and writes data from any source using standard io::Read and io::Write streams
  • Directives in attributes handle common binary parsing tasks like matching magic numbers, byte ordering, padding & alignment, data validation, and more
  • Includes reusable types for common data structures like null-terminated strings and data indirection using offsets
  • Parses types from third-party crates using free functions or value maps
  • Uses efficient in-memory representations (does not require #[repr(C)] or #[repr(packed)])
  • Code in attributes is written as code, not as strings, for improved ergonomics and first-class IDE support
  • Supports no_std

Usage

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

For more information, including a more detailed overview of binrw, visit the documentation.

binrw's People

Contributors

jam1garner avatar csnover avatar mrnbayoh avatar kitlith avatar dmgolembiowski avatar octylfractal avatar roblabla avatar holzhaus avatar nicenenerd avatar r4v3n6101 avatar scanmountgoat avatar amperl avatar benhall-7 avatar apanatshka avatar redstrate avatar timotree3 avatar colinfinck avatar joseluis avatar skirmisher avatar jerry73204 avatar leo60228 avatar

Watchers

James Cloos avatar  avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.