[−][src]Crate deku
Deku: Declarative binary reading and writing
This crate provides bit-level, symmetric, serialization/deserialization implementations for your structs and enums This allows the developer to focus on building and maintaining the representation of data and not on serialization/deserialization code.
This approach is especially useful when dealing with binary structures or network protocols
Under the hood, it makes use of the bitvec crate as the "Reader" and “Writer”
For documentation on #deku[()]
attributes see attributes list
Example
use deku::prelude::*; #[derive(Debug, PartialEq, DekuRead, DekuWrite)] #[deku(endian = "big")] struct DekuTest { #[deku(bits = "4")] field_a: u8, #[deku(bits = "4")] field_b: u8, field_c: u16, } let data: &[u8] = [0b0110_1001, 0xBE, 0xEF].as_ref(); let (_rest, mut val) = DekuTest::from_bytes((data, 0)).unwrap(); assert_eq!(DekuTest { field_a: 0b0110, field_b: 0b1001, field_c: 0xBEEF, }, val); val.field_c = 0xC0FE; let data_out = val.to_bytes(); assert_eq!(vec![0b0110_1001, 0xC0, 0xFE], data_out);
Modules
attributes | A documentation-only module for #[deku] attributes |
error | |
prelude |
Traits
BitsReader | "Reader" trait: read bits and construct type |
BitsWriter | "Writer" trait: write from type to bits |
Derive Macros
DekuRead | |
DekuWrite |