1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
use super::{ChunkType, Crc32};

/// The smallest data unit in PNA
pub trait Chunk {
    /// Byte size of data
    #[inline]
    fn length(&self) -> u32 {
        self.data().len() as u32
    }
    /// Type of chunk
    fn ty(&self) -> ChunkType;
    /// Data of chunk
    fn data(&self) -> &[u8];
    /// CRC32 of chunk type and data
    fn crc(&self) -> u32 {
        let mut crc = Crc32::new();
        crc.update(&self.ty().0);
        crc.update(self.data());
        crc.finalize()
    }
}