MCPcopy Create free account
hub / github.com/base/base / decode

Method decode

crates/proof/mpt/src/node.rs:569–604  ·  view source on GitHub ↗

Attempts to decode the [`TrieNode`].

(buf: &mut &[u8])

Source from the content-addressed store, hash-verified

567impl Decodable for TrieNode {
568 /// Attempts to decode the [`TrieNode`].
569 fn decode(buf: &mut &[u8]) -> alloy_rlp::Result<Self> {
570 // Peek at the header to determine the type of Trie node we're currently decoding.
571 let header = Header::decode(&mut (**buf).as_ref())?;
572
573 if header.list {
574 // Peek at the RLP stream to determine the number of elements in the list.
575 let list_length = rlp_list_element_length(&mut (**buf).as_ref())?;
576
577 match list_length {
578 BRANCH_LIST_LENGTH => {
579 let list = Vec::<Self>::decode(buf)?;
580 Ok(Self::Branch { stack: list })
581 }
582 LEAF_OR_EXTENSION_LIST_LENGTH => {
583 // Advance the buffer to the start of the list payload.
584 buf.advance(header.length());
585 // Decode the leaf or extension node's raw payload.
586 Self::try_decode_leaf_or_extension_payload(buf)
587 .map_err(|_| alloy_rlp::Error::UnexpectedList)
588 }
589 _ => Err(alloy_rlp::Error::UnexpectedLength),
590 }
591 } else {
592 match header.payload_length {
593 0 => {
594 buf.advance(header.length());
595 Ok(Self::Empty)
596 }
597 32 => {
598 let commitment = B256::decode(buf)?;
599 Ok(Self::new_blinded(commitment))
600 }
601 _ => Err(alloy_rlp::Error::UnexpectedLength),
602 }
603 }
604 }
605}
606
607#[cfg(test)]

Callers

nothing calls this directly

Calls 4

rlp_list_element_lengthFunction · 0.85
as_refMethod · 0.45
advanceMethod · 0.45
lengthMethod · 0.45

Tested by

no test coverage detected