[][src]Trait trie_db::NodeCodec

pub trait NodeCodec<H: Hasher>: Sized {
    type Error: Error;
    fn hashed_null_node() -> H::Out;
fn decode(data: &[u8]) -> Result<Node, Self::Error>;
fn try_decode_hash(data: &[u8]) -> Option<H::Out>;
fn is_empty_node(data: &[u8]) -> bool;
fn empty_node() -> &'static [u8];
fn leaf_node(partial: Partial, value: &[u8]) -> Vec<u8>;
fn extension_node(
        partial: impl Iterator<Item = u8>,
        number_nibble: usize,
        child_ref: ChildReference<H::Out>
    ) -> Vec<u8>;
fn branch_node(
        children: impl Iterator<Item = impl Borrow<Option<ChildReference<H::Out>>>>,
        value: Option<&[u8]>
    ) -> Vec<u8>;
fn branch_node_nibbled(
        partial: impl Iterator<Item = u8>,
        number_nibble: usize,
        children: impl Iterator<Item = impl Borrow<Option<ChildReference<H::Out>>>>,
        value: Option<&[u8]>
    ) -> Vec<u8>; }

Trait for trie node encoding/decoding.

Associated Types

type Error: Error

Codec error type.

Loading content...

Required methods

fn hashed_null_node() -> H::Out

Get the hashed null node.

fn decode(data: &[u8]) -> Result<Node, Self::Error>

Decode bytes to a Node. Returns Self::E on failure.

fn try_decode_hash(data: &[u8]) -> Option<H::Out>

Decode bytes to the Hashers output type. Returns None on failure.

fn is_empty_node(data: &[u8]) -> bool

Check if the provided bytes correspond to the codecs "empty" node.

fn empty_node() -> &'static [u8]

Returns an encoded empty node.

fn leaf_node(partial: Partial, value: &[u8]) -> Vec<u8>

Returns an encoded leaf node

fn extension_node(
    partial: impl Iterator<Item = u8>,
    number_nibble: usize,
    child_ref: ChildReference<H::Out>
) -> Vec<u8>

Returns an encoded extension node Note that number_nibble is the number of element of the iterator it can possibly be obtain by Iterator size_hint, but for simplicity it is used directly as a parameter.

fn branch_node(
    children: impl Iterator<Item = impl Borrow<Option<ChildReference<H::Out>>>>,
    value: Option<&[u8]>
) -> Vec<u8>

Returns an encoded branch node. Takes an iterator yielding ChildReference<H::Out> and an optional value.

fn branch_node_nibbled(
    partial: impl Iterator<Item = u8>,
    number_nibble: usize,
    children: impl Iterator<Item = impl Borrow<Option<ChildReference<H::Out>>>>,
    value: Option<&[u8]>
) -> Vec<u8>

Returns an encoded branch node with a possible partial path. number_nibble is the partial path length as in extension_node.

Loading content...

Implementors

Loading content...