pub trait NodeCodec: Sized {
type Error: Error;
type HashOut: AsRef<[u8]> + AsMut<[u8]> + Default + MaybeDebug + PartialEq + Eq + Hash + Send + Sync + Clone + Copy;
const ESCAPE_HEADER: Option<u8> = None;
// Required methods
fn hashed_null_node() -> Self::HashOut;
fn decode_plan(data: &[u8]) -> Result<NodePlan, Self::Error>;
fn is_empty_node(data: &[u8]) -> bool;
fn empty_node() -> &'static [u8] ⓘ;
fn leaf_node(
partial: impl Iterator<Item = u8>,
number_nibble: usize,
value: Value<'_>
) -> Vec<u8> ⓘ;
fn extension_node(
partial: impl Iterator<Item = u8>,
number_nibble: usize,
child_ref: ChildReference<Self::HashOut>
) -> Vec<u8> ⓘ;
fn branch_node(
children: impl Iterator<Item = impl Borrow<Option<ChildReference<Self::HashOut>>>>,
value: Option<Value<'_>>
) -> Vec<u8> ⓘ;
fn branch_node_nibbled(
partial: impl Iterator<Item = u8>,
number_nibble: usize,
children: impl Iterator<Item = impl Borrow<Option<ChildReference<Self::HashOut>>>>,
value: Option<Value<'_>>
) -> Vec<u8> ⓘ;
// Provided method
fn decode<'a>(data: &'a [u8]) -> Result<Node<'a>, Self::Error> { ... }
}
Expand description
Trait for trie node encoding/decoding. Uses a type parameter to allow registering positions without colling decode plan.
Required Associated Types§
Provided Associated Constants§
sourceconst ESCAPE_HEADER: Option<u8> = None
const ESCAPE_HEADER: Option<u8> = None
Escape header byte sequence to indicate next node is a branch or leaf with hash of value, followed by the value node.
Required Methods§
sourcefn hashed_null_node() -> Self::HashOut
fn hashed_null_node() -> Self::HashOut
Get the hashed null node.
sourcefn decode_plan(data: &[u8]) -> Result<NodePlan, Self::Error>
fn decode_plan(data: &[u8]) -> Result<NodePlan, Self::Error>
Decode bytes to a NodePlan
. Returns Self::E
on failure.
sourcefn is_empty_node(data: &[u8]) -> bool
fn is_empty_node(data: &[u8]) -> bool
Check if the provided bytes correspond to the codecs “empty” node.
sourcefn empty_node() -> &'static [u8] ⓘ
fn empty_node() -> &'static [u8] ⓘ
Returns an encoded empty node.
sourcefn leaf_node(
partial: impl Iterator<Item = u8>,
number_nibble: usize,
value: Value<'_>
) -> Vec<u8> ⓘ
fn leaf_node( partial: impl Iterator<Item = u8>, number_nibble: usize, value: Value<'_> ) -> Vec<u8> ⓘ
Returns an encoded leaf 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.
sourcefn extension_node(
partial: impl Iterator<Item = u8>,
number_nibble: usize,
child_ref: ChildReference<Self::HashOut>
) -> Vec<u8> ⓘ
fn extension_node( partial: impl Iterator<Item = u8>, number_nibble: usize, child_ref: ChildReference<Self::HashOut> ) -> 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.
sourcefn branch_node(
children: impl Iterator<Item = impl Borrow<Option<ChildReference<Self::HashOut>>>>,
value: Option<Value<'_>>
) -> Vec<u8> ⓘ
fn branch_node( children: impl Iterator<Item = impl Borrow<Option<ChildReference<Self::HashOut>>>>, value: Option<Value<'_>> ) -> Vec<u8> ⓘ
Returns an encoded branch node.
Takes an iterator yielding ChildReference<Self::HashOut>
and an optional value.
sourcefn branch_node_nibbled(
partial: impl Iterator<Item = u8>,
number_nibble: usize,
children: impl Iterator<Item = impl Borrow<Option<ChildReference<Self::HashOut>>>>,
value: Option<Value<'_>>
) -> Vec<u8> ⓘ
fn branch_node_nibbled( partial: impl Iterator<Item = u8>, number_nibble: usize, children: impl Iterator<Item = impl Borrow<Option<ChildReference<Self::HashOut>>>>, value: Option<Value<'_>> ) -> Vec<u8> ⓘ
Returns an encoded branch node with a possible partial path.
number_nibble
is the partial path length as in extension_node
.