in src/proof.rs [249:291]
fn deserialize_as_a_unit(
bytes: &[u8],
begin: &mut usize,
) -> Result<MerkleProof<V>, DecodingError> {
// Return empty proof if the input byte is empty.
if bytes.len() - *begin == 0 {
return Ok(MerkleProof::new_batch(&[] as &[TreeIndex]));
}
// Decode the batch_num.
let num = bytes_to_usize(bytes, BATCH_NUM_BYTE_NUM, begin);
if let Err(e) = num {
return Err(e);
}
let num = num.unwrap();
// Decode the tree indexes.
let index = TreeIndex::deserialize_as_a_unit(bytes, num, begin);
if let Err(e) = index {
return Err(e);
}
let index = index.unwrap();
let mut proof: MerkleProof<V> = MerkleProof::new_batch(&index);
// Decode the sibling_num.
let sibling_num = bytes_to_usize(bytes, SIBLING_NUM_BYTE_NUM, begin);
if let Err(e) = sibling_num {
return Err(e);
}
let sibling_num = sibling_num.unwrap();
// Decode the siblings.
let mut siblings: Vec<V::ProofNode> = Vec::new();
for _i in 0..sibling_num {
let sibling = V::ProofNode::deserialize_as_a_unit(bytes, begin);
if let Err(e) = sibling {
return Err(e);
}
siblings.push(sibling.unwrap());
}
proof.set_siblings(siblings);
Ok(proof)
}