Trait ipld_core::codec::Codec

source ·
pub trait Codec<T>: Links {
    type Error;

    const CODE: u64;

    // Required methods
    fn decode<R: BufRead>(reader: R) -> Result<T, Self::Error>;
    fn encode<W: Write>(writer: W, data: &T) -> Result<(), Self::Error>;

    // Provided methods
    fn decode_from_slice(bytes: &[u8]) -> Result<T, Self::Error> { ... }
    fn encode_to_vec(data: &T) -> Result<Vec<u8>, Self::Error> { ... }
}
Expand description

Each IPLD codec implementation should implement this Codec trait. This way codecs can be more easily exchanged or combined.

Required Associated Types§

source

type Error

The error that is returned if encoding or decoding fails.

Required Associated Constants§

source

const CODE: u64

The multicodec code of the IPLD codec.

Required Methods§

source

fn decode<R: BufRead>(reader: R) -> Result<T, Self::Error>

Decode a reader into the desired type.

source

fn encode<W: Write>(writer: W, data: &T) -> Result<(), Self::Error>

Encode a type into a writer.

Provided Methods§

source

fn decode_from_slice(bytes: &[u8]) -> Result<T, Self::Error>

Decode a slice into the desired type.

source

fn encode_to_vec(data: &T) -> Result<Vec<u8>, Self::Error>

Encode a type into bytes.

Object Safety§

This trait is not object safe.

Implementors§