Codec

Trait Codec 

Source
pub trait Codec
where Self: Clone, Self::Payload: Serialize + DeserializeOwned,
{ type Payload; // Required methods fn encode(&self, payload: &Self::Payload) -> Result<Vec<u8>>; fn decode(&self, encoded_value: &[u8]) -> Result<Self::Payload>; }
Expand description

A pluggable payload encoder/decoder.

See the module-level documentation for detailed guidance and examples.

Required Associated Types§

Source

type Payload

Type of the payload being encoded/decoded.

Required Methods§

Source

fn encode(&self, payload: &Self::Payload) -> Result<Vec<u8>>

Encode a payload into an opaque, implementation-defined byte vector.

Implementations MUST:

  • Serialize + sign / encrypt (where applicable)
  • Return an error if encoding or cryptographic operations fail
Source

fn decode(&self, encoded_value: &[u8]) -> Result<Self::Payload>

Decode a previously encoded payload.

Implementations MUST:

  • Fully validate integrity/authenticity (e.g. signature/MAC) before returning
  • Reject malformed or tampered data with an appropriate error

Dyn Compatibility§

This trait is not dyn compatible.

In older versions of Rust, dyn compatibility was called "object safety", so this trait is not object safe.

Implementors§