SparseMerklePath: implement Serializable and Deserializable
This commit is contained in:
parent
258315226e
commit
985723929c
1 changed files with 23 additions and 0 deletions
|
@ -196,6 +196,29 @@ impl DoubleEndedIterator for SparseMerkleIter {
|
|||
}
|
||||
}
|
||||
|
||||
// SERIALIZATION
|
||||
// ================================================================================================
|
||||
|
||||
impl Serializable for SparseMerklePath {
|
||||
fn write_into<W: winter_utils::ByteWriter>(&self, target: &mut W) {
|
||||
target.write_u8(self.depth());
|
||||
target.write_u64(self.empty_nodes);
|
||||
target.write_many(&self.nodes);
|
||||
}
|
||||
}
|
||||
|
||||
impl Deserializable for SparseMerklePath {
|
||||
fn read_from<R: winter_utils::ByteReader>(
|
||||
source: &mut R,
|
||||
) -> Result<Self, DeserializationError> {
|
||||
let depth = source.read_u8()?;
|
||||
let empty_nodes = source.read_u64()?;
|
||||
let count = depth as u32 - empty_nodes.count_ones();
|
||||
let nodes = source.read_many::<RpoDigest>(count as usize)?;
|
||||
Ok(Self { empty_nodes, nodes })
|
||||
}
|
||||
}
|
||||
|
||||
#[cfg(test)]
|
||||
mod tests {
|
||||
use alloc::vec::Vec;
|
||||
|
|
Loading…
Add table
Reference in a new issue