MCPcopy Create free account
hub / github.com/base/triedb / encode_branch

Function encode_branch

src/node.rs:661–684  ·  view source on GitHub ↗
(children: &[Option<Pointer>], out: &mut dyn BufMut)

Source from the content-addressed store, hash-verified

659
660#[inline]
661pub fn encode_branch(children: &[Option<Pointer>], out: &mut dyn BufMut) -> usize {
662 // first encode the header
663 let mut payload_length = 1;
664 for child in children.iter() {
665 if let Some(child) = child {
666 payload_length += child.rlp().len();
667 } else {
668 payload_length += 1;
669 }
670 }
671 Header { list: true, payload_length }.encode(out);
672 // now encode the children
673 for child in children.iter() {
674 if let Some(child) = child {
675 out.put_slice(child.rlp());
676 } else {
677 out.put_u8(EMPTY_STRING_CODE);
678 }
679 }
680 // and encode the empty 17th slot
681 out.put_u8(EMPTY_STRING_CODE);
682
683 payload_length + length_of_length(payload_length)
684}
685
686fn arb_children() -> impl Strategy<Value = [Option<Pointer>; 16]> {
687 (proptest::collection::vec(arbitrary::any::<Pointer>(), 2..16), 1..15).prop_map(

Callers 3

encodeMethod · 0.85

Calls 4

rlpMethod · 0.80
encodeMethod · 0.80
iterMethod · 0.45
lenMethod · 0.45

Tested by

no test coverage detected