https://github.com/mxk/structbuf-rs
Capacity-limited buffer for structured data
https://github.com/mxk/structbuf-rs
Last synced: 8 months ago
JSON representation
Capacity-limited buffer for structured data
- Host: GitHub
- URL: https://github.com/mxk/structbuf-rs
- Owner: mxk
- License: mpl-2.0
- Created: 2022-12-12T03:32:14.000Z (about 3 years ago)
- Default Branch: main
- Last Pushed: 2023-02-18T02:55:09.000Z (almost 3 years ago)
- Last Synced: 2025-04-13T03:49:40.843Z (8 months ago)
- Language: Rust
- Size: 21.5 KB
- Stars: 2
- Watchers: 2
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE.md
Awesome Lists containing this project
README
StructBuf
=========
[](https://crates.io/crates/structbuf)
[](https://docs.rs/structbuf)
[](https://choosealicense.com/licenses/mpl-2.0/)
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
```
```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();
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());
```