bitwrap is a derive macro and interface to declare a struct data member with explicit size, in bits.
```rust use bitwrap::*;
struct Packet { #[bits(1)] f1: u8, #[bits(1)] f2: u8, #[bits(2)] f3: u8, #[bits(4)] f4: u8, #[bits(16)] f5: u16, }
const DATA: &[u8] = &[0xAA, 0x12, 0x34];
let mut packet = Packet::default(); packet.unpack(DATA);
asserteq!(packet.f1, 1); asserteq!(packet.f2, 0); asserteq!(packet.f3, 2); asserteq!(packet.f4, 0x0A); assert_eq!(packet.f5, 0x1234);
let mut buffer: Vec
asserteq!(buffer.asslice(), DATA); ```
```rust use bitwrap::*;
struct Field { #[bits(1)] f1: u8, #[bits(1)] f2: u8, #[bits(2)] f3: u8, #[bits(4)] f4: u8, }
struct Packet { #[bitwrap] nested: Field, #[bits(16)] f1: u16, }
const DATA: &[u8] = &[0xAA, 0x12, 0x34];
let mut packet = Packet::default(); packet.unpack(DATA);
asserteq!(packet.nested.f1, 1); asserteq!(packet.nested.f2, 0); asserteq!(packet.nested.f3, 2); asserteq!(packet.nested.f4, 0x0A); assert_eq!(packet.f1, 0x1234);
let mut buffer: Vec
asserteq!(buffer.asslice(), DATA); ```