structbuf

Crates.iostructbuf
lib.rsstructbuf
version0.3.4
sourcesrc
created_at2022-12-12 03:57:18.644731
updated_at2023-02-18 02:55:21.343316
descriptionCapacity-limited structured data buffer
homepage
repositoryhttps://github.com/mxk/structbuf-rs
max_upload_size
id734714
size45,512
Maxim Khitrov (mxk)

documentation

README

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());
Commit count: 12

cargo fmt