arrange constants
This commit is contained in:
parent
de053e1d8f
commit
49763d1c01
|
@ -204,5 +204,4 @@ fn main() {
|
|||
|
||||
let tree = prepare_tree(initial_tree_vec);
|
||||
println!("root: {}", tree.root());
|
||||
|
||||
}
|
|
@ -1,6 +1,8 @@
|
|||
use byteorder::{LittleEndian, ReadBytesExt};
|
||||
|
||||
use crate::{EntryKind, NodeData, Error, EntryLink};
|
||||
use crate::{EntryKind, NodeData, Error, EntryLink, MAX_NODE_DATA_SIZE};
|
||||
|
||||
pub const MAX_ENTRY_SIZE: usize = MAX_NODE_DATA_SIZE + 9;
|
||||
|
||||
#[derive(Debug)]
|
||||
pub struct Entry {
|
||||
|
|
|
@ -7,8 +7,8 @@ mod node_data;
|
|||
mod entry;
|
||||
|
||||
pub use tree::Tree;
|
||||
pub use node_data::NodeData;
|
||||
pub use entry::Entry;
|
||||
pub use node_data::{NodeData, MAX_NODE_DATA_SIZE};
|
||||
pub use entry::{Entry, MAX_ENTRY_SIZE};
|
||||
|
||||
#[derive(Debug, derive_more::Display)]
|
||||
pub enum Error {
|
||||
|
|
|
@ -2,6 +2,8 @@ use byteorder::{LittleEndian, ReadBytesExt, WriteBytesExt, ByteOrder};
|
|||
use bigint::U256;
|
||||
use blake2::blake2b::Blake2b;
|
||||
|
||||
pub const MAX_NODE_DATA_SIZE: usize = 32 + 4 + 4 + 4 + 4 + 32 + 32 + 32 + 9 + 9 + 9; // 171
|
||||
|
||||
/// Node metadata.
|
||||
#[repr(C)]
|
||||
#[derive(Debug, Clone, Default)]
|
||||
|
@ -36,12 +38,10 @@ fn personalization(branch_id: u32) -> [u8; 16] {
|
|||
}
|
||||
|
||||
impl NodeData {
|
||||
pub const MAX_SERIALIZED_SIZE: usize = 32 + 4 + 4 + 4 + 4 + 32 + 32 + 32 + 9 + 9 + 9; // =171;
|
||||
|
||||
pub fn combine(left: &NodeData, right: &NodeData) -> NodeData {
|
||||
assert_eq!(left.consensus_branch_id, right.consensus_branch_id);
|
||||
|
||||
let mut hash_buf = [0u8; Self::MAX_SERIALIZED_SIZE * 2];
|
||||
let mut hash_buf = [0u8; MAX_NODE_DATA_SIZE * 2];
|
||||
let size = {
|
||||
let mut cursor = ::std::io::Cursor::new(&mut hash_buf[..]);
|
||||
left.write(&mut cursor).expect("Writing to memory buf with enough length cannot fail; qed");
|
||||
|
@ -144,7 +144,7 @@ impl NodeData {
|
|||
}
|
||||
|
||||
pub fn to_bytes(&self) -> Vec<u8> {
|
||||
let mut buf = [0u8; Self::MAX_SERIALIZED_SIZE];
|
||||
let mut buf = [0u8; MAX_NODE_DATA_SIZE];
|
||||
let pos = {
|
||||
let mut cursor = std::io::Cursor::new(&mut buf[..]);
|
||||
self.write(&mut cursor).expect("Cursor cannot fail");
|
||||
|
|
Loading…
Reference in New Issue