[][src]Trait ipld::CodecExt

pub trait CodecExt: Codec {
    fn encode<S>(dag: &S) -> Result<Box<[u8]>, Self::Error>
    where
        S: Serialize
;
fn decode<'de, D>(bytes: &'de [u8]) -> Result<D, Self::Error>
    where
        D: Deserialize<'de>
; fn write<S, W>(dag: &S, writer: W) -> Result<(), Self::Error>
    where
        S: Serialize,
        W: Write
, { ... }
fn read<D, R>(reader: R) -> Result<D, Self::Error>
    where
        D: DeserializeOwned,
        R: Read
, { ... }
fn serialize_bytes<S>(
        bytes: &[u8],
        serializer: S
    ) -> Result<S::Ok, S::Error>
    where
        S: Serializer
, { ... }
fn serialize_link<S>(cid: &Cid, serializer: S) -> Result<S::Ok, S::Error>
    where
        S: Serializer
, { ... }
fn deserialize_unknown<'de, D, V>(
        deserializer: D,
        visitor: V
    ) -> Result<V::Value, D::Error>
    where
        D: Deserializer<'de>,
        V: IpldVisitor<'de>
, { ... } }

Extension trait for Codecs that can delegate to serde.

Required methods

fn encode<S>(dag: &S) -> Result<Box<[u8]>, Self::Error> where
    S: Serialize

Given a dag, serialize it to bytes.

fn decode<'de, D>(bytes: &'de [u8]) -> Result<D, Self::Error> where
    D: Deserialize<'de>, 

Given some bytes, deserialize it to a dag.

Loading content...

Provided methods

fn write<S, W>(dag: &S, writer: W) -> Result<(), Self::Error> where
    S: Serialize,
    W: Write

Given a Write, serialize it to bytes.

Panics by default.

fn read<D, R>(reader: R) -> Result<D, Self::Error> where
    D: DeserializeOwned,
    R: Read

Given a Read, deserialize it to a dag.

Panics by default.

fn serialize_bytes<S>(bytes: &[u8], serializer: S) -> Result<S::Ok, S::Error> where
    S: Serializer

Because some codecs are text-based rather than binary, Codecs may define custom default behaviour for serializing bytes.

Serialize an IPLD link.

Default behaviour is to serialize the link directly as bytes.

fn deserialize_unknown<'de, D, V>(
    deserializer: D,
    visitor: V
) -> Result<V::Value, D::Error> where
    D: Deserializer<'de>,
    V: IpldVisitor<'de>, 

Deserialize an unknown Serde type.

Because the IPLD data model doesn't map 1:1 with the Serde data model, a type's Visitor may be asked to visit an enum or a newtype struct. In these cases, the type can hand off

Loading content...

Implementors

Loading content...