#buffer #parser #vec #networking #data-encoding #codec

无 std structbuf

容量限制的结构化数据缓冲区

7 个版本

0.3.4 2023 年 2 月 18 日
0.3.3 2023 年 1 月 28 日
0.3.1 2022 年 12 月 19 日
0.2.0 2022 年 12 月 13 日
0.1.0 2022 年 12 月 12 日

#1611解析器实现

每月 29 下载量
4 包(3 个直接)中使用

MPL-2.0 许可证

29KB
578

StructBuf

crates.io docs.rs License

此库提供了一种容量限制的缓冲区,用于编码和解码结构化数据。主要用例是安全处理通过网络或其他传输发送的小型、可变长度的消息数据包。

编码器确保消息大小永远不会超过预先配置的限制。解码器确保格式错误或恶意输入不会导致程序崩溃。

no_std 支持

structbuf 默认为 no_std

示例

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());

依赖关系

~73KB