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() -> Vec<u8>;
fn leaf_node(partial: &[u8], value: &[u8]) -> Vec<u8>;
fn ext_node(partial: &[u8], child_ref: ChildReference<H::Out>) -> Vec<u8>;
fn branch_node<I>(
children: I,
value: Option<ElasticArray128<u8>>
) -> Vec<u8>
where
I: IntoIterator<Item = Option<ChildReference<H::Out>>> + Iterator<Item = Option<ChildReference<H::Out>>>;
}
Expand description
Trait for trie node encoding/decoding
Associated Types
Required methods
fn hashed_null_node() -> H::Out
fn hashed_null_node() -> H::Out
Get the hashed null node.
Decode bytes to a Node
. Returns Self::E
on failure.
Decode bytes to the Hasher
s output type. Returns None
on failure.
Check if the provided bytes correspond to the codecs “empty” node.
fn empty_node() -> Vec<u8>
fn empty_node() -> Vec<u8>
Returns an empty node
Returns an encoded extension node
fn branch_node<I>(children: I, value: Option<ElasticArray128<u8>>) -> Vec<u8> where
I: IntoIterator<Item = Option<ChildReference<H::Out>>> + Iterator<Item = Option<ChildReference<H::Out>>>,
fn branch_node<I>(children: I, value: Option<ElasticArray128<u8>>) -> Vec<u8> where
I: IntoIterator<Item = Option<ChildReference<H::Out>>> + Iterator<Item = Option<ChildReference<H::Out>>>,
Returns an encoded branch node. Takes an iterator yielding ChildReference<H::Out>
and an optional value