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§
Required Associated Constants§
Required Methods§
Provided Methods§
sourcefn decode_from_slice(bytes: &[u8]) -> Result<T, Self::Error>
fn decode_from_slice(bytes: &[u8]) -> Result<T, Self::Error>
Decode a slice into the desired type.
Object Safety§
This trait is not object safe.