Attempts to decode the [`TrieNode`].
(buf: &mut &[u8])
| 567 | impl 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)] |
nothing calls this directly
no test coverage detected