Skip to main content

xet_core_structures/xorb_object/
chunk.rs

1use bytes::Bytes;
2
3use crate::merklehash::{MerkleHash, compute_data_hash};
4
5#[derive(Debug, Clone, PartialEq)]
6pub struct Chunk {
7    pub hash: MerkleHash,
8    pub data: Bytes,
9}
10
11impl Chunk {
12    pub fn new(data: Bytes) -> Self {
13        Chunk {
14            hash: compute_data_hash(&data),
15            data,
16        }
17    }
18}
19
20impl AsRef<[u8]> for Chunk {
21    fn as_ref(&self) -> &[u8] {
22        self.data.as_ref()
23    }
24}