pub trait AFastSerialize {
// Required method
fn to_bytes(&self) -> Vec<u8> ⓘ;
}Expand description
序列化 trait,为类型提供转换为字节数组的能力。
Serialization trait that provides the ability to convert a type into a byte array.
§编码规则 / Encoding Rules
实现者应确保 to_bytes() 输出的字节流能够被对应的 AFastDeserialize::from_bytes
完整还原。字节序统一使用 小端序 (little-endian)。
Implementors must ensure that the byte output of to_bytes() can be fully
restored by the corresponding AFastDeserialize::from_bytes. All multi-byte
values use little-endian byte order.
§示例 / Example
ⓘ
use afastdata::AFastSerialize;
let value: i32 = 42;
let bytes = value.to_bytes();
assert_eq!(bytes, vec![42, 0, 0, 0]);Required Methods§
Implementations on Foreign Types§
Source§impl AFastSerialize for &str
impl AFastSerialize for &str
Source§impl AFastSerialize for bool
impl AFastSerialize for bool
Source§impl AFastSerialize for f32
impl AFastSerialize for f32
Source§impl AFastSerialize for f64
impl AFastSerialize for f64
Source§impl AFastSerialize for i8
impl AFastSerialize for i8
Source§impl AFastSerialize for i16
impl AFastSerialize for i16
Source§impl AFastSerialize for i32
impl AFastSerialize for i32
Source§impl AFastSerialize for i64
impl AFastSerialize for i64
Source§impl AFastSerialize for i128
impl AFastSerialize for i128
Source§impl AFastSerialize for u8
impl AFastSerialize for u8
Source§impl AFastSerialize for u16
impl AFastSerialize for u16
Source§impl AFastSerialize for u32
impl AFastSerialize for u32
Source§impl AFastSerialize for u64
impl AFastSerialize for u64
Source§impl AFastSerialize for u128
impl AFastSerialize for u128
Source§impl AFastSerialize for String
impl AFastSerialize for String
Source§impl<T: AFastSerialize> AFastSerialize for Option<T>
impl<T: AFastSerialize> AFastSerialize for Option<T>
Source§impl<T: AFastSerialize> AFastSerialize for Vec<T>
impl<T: AFastSerialize> AFastSerialize for Vec<T>
Source§fn to_bytes(&self) -> Vec<u8> ⓘ
fn to_bytes(&self) -> Vec<u8> ⓘ
将向量序列化为:LenInt 元素个数前缀 + 逐个元素的序列化数据。
Serializes the vector as: LenInt element count prefix + serialized data for each element.
每个元素调用其自身的 to_bytes() 方法,所有元素的序列化结果依次拼接。
Each element’s to_bytes() method is called, and all serialized results are
concatenated sequentially.