/// Read a MerkleTree from a reader.
Read a MerkleTree from a reader.
Read a MerkleTree from a reader .
pub fn read<R: Read>(
        mut reader: R,
        tree_type: TreeType,
        depth: usize,
    ) -> std::io::Result<MerkleTree> {
        let mut tree = MerkleTree::new(tree_type, depth);
        let mut last_filled_position = [0; 16];
        reader.read_exact(&mut last_filled_position)?;
        tree.last_filled_position = u8_array_to_u128(&last_filled_position);
        let mut option = [0; 1];
        reader.read_exact(&mut option)?;
        match option[0] {
            0 => tree.left = None,
            1 => tree.left = Some(MerkleNode::read(reader.by_ref())?),
            _ => {
                return Err(std::io::Error::new(
                    std::io::ErrorKind::Other,
                    "Cannot read tree.",
                ));
            }
        }
        reader.read_exact(&mut option)?;
        match option[0] {
            0 => tree.right = None,
            1 => tree.right = Some(MerkleNode::read(reader.by_ref())?),
            _ => {
                return Err(std::io::Error::new(
                    std::io::ErrorKind::Other,
                    "Cannot read tree.",
                ));
            }
        }
        let mut parent_amount = [0; 8];
        reader.read_exact(&mut parent_amount)?;
        let parent_amount = u8_array_to_u64(&parent_amount);
        for _ in 0..parent_amount {
            reader.read_exact(&mut option)?;
            match option[0] {
                0 => tree.parents.push(None),
                1 => tree.parents.push(Some(MerkleNode::read(reader.by_ref())?)),
                _ => {
                    return Err(std::io::Error::new(
                        std::io::ErrorKind::Other,
                        "Cannot read tree.",
                    ));
                }
            }
        }
        Ok(tree)
    }
pub fn read < R : Read > ( mut reader : R , tree_type : TreeType , depth : usize , ) -> std :: io :: Result < MerkleTree > { let mut tree = MerkleTree :: new ( tree_type , depth ) ; let mut last_filled_position = [ 0 ; 16 ] ; reader . read_exact ( & mut last_filled_position ) ? ; tree . last_filled_position = u8_array_to_u128 ( & last_filled_position ) ; let mut option = [ 0 ; 1 ] ; reader . read_exact ( & mut option ) ? ; match option [ 0 ] { 0 => tree . left = None , 1 => tree . left = Some ( MerkleNode :: read ( reader . by_ref ( ) ) ? ) , _ => { return Err ( std :: io :: Error :: new ( std :: io :: ErrorKind :: Other , " " , ) ) ; } } reader . read_exact ( & mut option ) ? ; match option [ 0 ] { 0 => tree . right = None , 1 => tree . right = Some ( MerkleNode :: read ( reader . by_ref ( ) ) ? ) , _ => { return Err ( std :: io :: Error :: new ( std :: io :: ErrorKind :: Other , " " , ) ) ; } } let mut parent_amount = [ 0 ; 8 ] ; reader . read_exact ( & mut parent_amount ) ? ; let parent_amount = u8_array_to_u64 ( & parent_amount ) ; for _ in 0 .. parent_amount { reader . read_exact ( & mut option ) ? ; match option [ 0 ] { 0 => tree . parents . push ( None ) , 1 => tree . parents . push ( Some ( MerkleNode :: read ( reader . by_ref ( ) ) ? ) ) , _ => { return Err ( std :: io :: Error :: new ( std :: io :: ErrorKind :: Other , " " , ) ) ; } } } Ok ( tree ) }
Read a MerkleTree from a reader.
Read a MerkleTree from a reader .
reader
R
tree_type
TreeType
depth
usize