Skip to main content

Codec

Trait Codec 

Source
pub trait Codec<T> {
    // Required methods
    fn encode(&self, value: &T) -> Result<Vec<u8>, CodecError>;
    fn decode(&self, bytes: &[u8]) -> Result<T, CodecError>;
}
Expand description

Encodes a message type to bytes for the store and decodes it back.

The typed layer (TypedProducer / TypedConsumer) is generic over this trait: implement it for a custom format, or use a built-in like [Bincode] behind the serde feature.

Required Methods§

Source

fn encode(&self, value: &T) -> Result<Vec<u8>, CodecError>

Encode value to bytes.

Source

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

Decode a value from bytes.

Dyn Compatibility§

This trait is dyn compatible.

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

Implementors§