Codec

Trait Codec 

Source
pub trait Codec {
    type Value;
    type Encoded: AsRef<[u8]>;

    // Required methods
    fn encode(d: &Self::Value) -> Option<Self::Encoded>;
    fn decode(bytes: &[u8]) -> Option<Self::Value>;
}
Expand description

A trait that defines how types are decoded/encoded.

Required Associated Types§

Required Methods§

Source

fn encode(d: &Self::Value) -> Option<Self::Encoded>

Source

fn decode(bytes: &[u8]) -> Option<Self::Value>

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§

Source§

impl Codec for NullCodec

Source§

impl<T> Codec for BinCodec<T>
where T: AsRef<[u8]> + From<Vec<u8>>,

Source§

impl<T> Codec for JsonCodec<T>

Source§

impl<T, R> Codec for ProtobufCodec<T, R>
where T: Into<R> + Clone, R: TryInto<T> + Default + Message,