Skip to main content

Crate afastdata

Crate afastdata 

Source
Expand description

§afastdata

高性能二进制序列化/反序列化库,通过 derive 宏为 Rust 类型自动生成序列化代码。

A high-performance binary serialization/deserialization library that automatically generates serialization code for Rust types via derive macros.

§编码规则 / Encoding Rules

类型 / Type编码方式 / Encoding
i8, u81 字节 little-endian / 1 byte little-endian
i16, u162 字节 little-endian / 2 bytes little-endian
i32, u324 字节 little-endian / 4 bytes little-endian
i64, u648 字节 little-endian / 8 bytes little-endian
i128, u12816 字节 little-endian / 16 bytes little-endian
f324 字节 IEEE 754 / 4 bytes IEEE 754
f648 字节 IEEE 754 / 8 bytes IEEE 754
bool1 字节,0x00=false,0x01=true / 1 byte, 0x00=false, 0x01=true
String长度前缀 (LenInt) + UTF-8 字节 / Length prefix (LenInt) + UTF-8 bytes
Vec<T>长度前缀 (LenInt) + 逐元素编码 / Length prefix (LenInt) + element-wise encoding
Option<T>标记字节 (0x00=None, 0x01=Some) + 数据(仅 Some 时)/ Tag byte (0x00=None, 0x01=Some) + data (only when Some)
[T; N]逐元素编码,无长度前缀 / Element-wise encoding, no length prefix
&str长度前缀 (LenInt) + UTF-8 字节(仅序列化)/ Length prefix (LenInt) + UTF-8 bytes (serialize only)

§长度前缀类型 / Length Prefix Type

默认使用 u32 作为长度前缀(最大 4GB),可通过启用 len-u64 feature 切换为 u64

By default, u32 is used as the length prefix (max 4GB). Enable the len-u64 feature to switch to u64.

Structs§

Error
afastdata 的核心错误类型。
ValidateError
用于更丰富错误构造的验证错误类型。

Enums§

ErrorKind
列举 afastdata 可能产生的错误类型。

Constants§

LEN_INT_SIZE
长度前缀类型的字节大小(u32 为 4,u64 为 8)。

Traits§

AFastDeserialize
反序列化 trait,为类型提供从字节数组还原的能力。
AFastSerialize
序列化 trait,为类型提供转换为字节数组的能力。

Type Aliases§

LenInt
长度前缀使用的整数类型。默认为 u32,启用 len-u64 feature 后为 u64

Derive Macros§

AFastDeserialize
Re-export derive 宏。
AFastSerialize
Re-export derive 宏。