Skip to main content

SaSerializer

Trait SaSerializer 

Source
pub trait SaSerializer: Send + Sync {
    // Required methods
    fn name(&self) -> &'static str;
    fn kind(&self, raw: &str) -> ValueKind;
    fn encode<T>(&self, value: &T) -> Result<String, SerializerError>
       where T: Serialize + ?Sized;
    fn decode<T>(&self, raw: &str) -> Result<T, SerializerError>
       where T: DeserializeOwned;

    // Provided methods
    fn encode_bytes<T>(&self, value: &T) -> Result<Vec<u8>, SerializerError>
       where T: Serialize + ?Sized { ... }
    fn decode_bytes<T>(&self, bytes: &[u8]) -> Result<T, SerializerError>
       where T: DeserializeOwned { ... }
}
Expand description

Pluggable serializer: domain object ↔ storage string | 可插拔序列化器:领域对象 ↔ 存储字符串

§Methods | 方法

  • name / kind / encode / decode — core String path | 核心 String 路径
  • encode_bytes / decode_bytes — optional zero-copy path (A2-3) | 可选零拷贝路径

Required Methods§

Source

fn name(&self) -> &'static str

Serializer identifier (e.g. “json”, “fory”) | 序列化器标识

Source

fn kind(&self, raw: &str) -> ValueKind

Detect payload format for rolling upgrades | 探测 payload 格式以支持滚动升级

Source

fn encode<T>(&self, value: &T) -> Result<String, SerializerError>
where T: Serialize + ?Sized,

Encode domain object to storage string | 编码领域对象为存储字符串

Errors: EncodeFailed on serde failure | 错误:serde 失败时 EncodeFailed

Source

fn decode<T>(&self, raw: &str) -> Result<T, SerializerError>

Decode storage string to domain object | 解码存储字符串为领域对象

Errors: DecodeFailed / FormatMismatch | 错误:DecodeFailed / FormatMismatch

Provided Methods§

Source

fn encode_bytes<T>(&self, value: &T) -> Result<Vec<u8>, SerializerError>
where T: Serialize + ?Sized,

Encode to bytes (default: UTF-8 of encode) | 编码为 bytes(默认委托 encode)

Source

fn decode_bytes<T>(&self, bytes: &[u8]) -> Result<T, SerializerError>

Decode from bytes (default: UTF-8 then decode) | 从 bytes 解码(默认 UTF-8 再 decode)

Dyn Compatibility§

This trait is not dyn compatible.

In older versions of Rust, dyn compatibility was called "object safety".

Implementors§