This library provides a capacity-limited buffer for encoding and decoding structured data. The primary use case is for safely handling small, variable-length message packets sent over the network or other transports.
The encoder ensures that the message size never exceeds a pre-configured limit. The decoder ensures that malformed or malicious input does not cause the program to panic.
no_std
supportstructbuf
is no_std
by default.
cargo add structbuf
```rust use structbuf::StructBuf;
let mut b = StructBuf::new(4); b.append().u8(1).u16(2_u16).u8(3); // b.u8(4); Would panic
let mut p = b.unpack(); asserteq!(p.u8(), 1); asserteq!(p.u16(), 2); asserteq!(p.u8(), 3); assert!(p.isok());
asserteq!(p.u32(), 0); assert!(!p.isok()); ```