Skip to main content

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

Encodes and decodes typed payloads.

Higher-level crates build on this small abstraction. A codec takes a typed payload, produces an opaque encoded representation, and can later decode that representation back into the typed payload.

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>>

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

Returns an error if serialization, signing, encryption, or other encoding steps fail.

Source

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

Decodes a previously encoded payload.

Returns an error if the value is malformed, tampered with, or otherwise fails integrity or authenticity validation.

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§