7 releases

0.3.4 Feb 18, 2023
0.3.3 Jan 28, 2023
0.3.1 Dec 19, 2022
0.2.0 Dec 13, 2022
0.1.0 Dec 12, 2022

#1027 in Parser implementations

Download history 4/week @ 2024-02-19 21/week @ 2024-02-26 16/week @ 2024-03-04 23/week @ 2024-03-11 13/week @ 2024-03-18 109/week @ 2024-03-25 83/week @ 2024-04-01

232 downloads per month
Used in 4 crates (3 directly)

MPL-2.0 license

29KB
578 lines

StructBuf

crates.io docs.rs License

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 support

structbuf is no_std by default.

Example

cargo add structbuf
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();
assert_eq!(p.u8(), 1);
assert_eq!(p.u16(), 2);
assert_eq!(p.u8(), 3);
assert!(p.is_ok());

assert_eq!(p.u32(), 0);
assert!(!p.is_ok());

Dependencies

~74KB