features
This commit is contained in:
@@ -1,5 +1,4 @@
|
||||
use rand::{Rng, rng};
|
||||
use sha2::{Digest, Sha256};
|
||||
use std::collections::HashMap;
|
||||
use std::hash::{DefaultHasher, Hash, Hasher};
|
||||
|
||||
@@ -283,29 +282,24 @@ impl MerkleNode {
|
||||
|
||||
pub fn serialize(&self) -> Vec<u8> {
|
||||
let mut bytes = Vec::new();
|
||||
// 1. Add the type byte
|
||||
bytes.push(self.get_type_byte());
|
||||
|
||||
// 2. Add the node-specific data
|
||||
match self {
|
||||
MerkleNode::Chunk(node) => {
|
||||
bytes.extend_from_slice(&node.data);
|
||||
}
|
||||
MerkleNode::Directory(node) => {
|
||||
// The data is the sequence of directory entries
|
||||
for entry in &node.entries {
|
||||
bytes.extend_from_slice(&entry.filename);
|
||||
bytes.extend_from_slice(&entry.content_hash);
|
||||
}
|
||||
}
|
||||
MerkleNode::Big(node) => {
|
||||
// The data is the list of child hashes
|
||||
for hash in &node.children_hashes {
|
||||
bytes.extend_from_slice(hash);
|
||||
}
|
||||
}
|
||||
MerkleNode::BigDirectory(node) => {
|
||||
// The data is the list of child hashes
|
||||
for hash in &node.children_hashes {
|
||||
bytes.extend_from_slice(hash);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user