| 602 | } |
| 603 | |
| 604 | fn length(&self) -> usize { |
| 605 | let prefix = self.prefix(); |
| 606 | match self.kind() { |
| 607 | NodeKind::StorageLeaf { .. } => { |
| 608 | // this just has to be an estimate for `Vec::with_capacity` |
| 609 | prefix.len() + 32 + 10 // 10 is just a buffer |
| 610 | } |
| 611 | NodeKind::AccountLeaf { .. } => { |
| 612 | // this just has to be an estimate for `Vec::with_capacity` |
| 613 | prefix.len() + 32 + 8 + 32 + 37 + 10 // 10 is just a buffer |
| 614 | } |
| 615 | NodeKind::Branch { children } => { |
| 616 | if prefix.is_empty() { |
| 617 | let mut payload_length = 1; |
| 618 | for child in children.iter() { |
| 619 | if let Some(child) = child { |
| 620 | payload_length += child.rlp().len(); |
| 621 | } else { |
| 622 | payload_length += 1; |
| 623 | } |
| 624 | } |
| 625 | payload_length + length_of_length(payload_length) |
| 626 | } else { |
| 627 | let mut encoded_key_len = prefix.len() / 2 + 1; |
| 628 | if encoded_key_len != 1 { |
| 629 | encoded_key_len += length_of_length(encoded_key_len); |
| 630 | } |
| 631 | let payload_length = encoded_key_len + 33; |
| 632 | payload_length + length_of_length(payload_length) |
| 633 | } |
| 634 | } |
| 635 | } |
| 636 | } |
| 637 | } |
| 638 | |
| 639 | #[inline] |