mod byte_block;
pub use byte_block::*;
use crate::payload::{PayloadEncoded, PayloadHooks};
pub trait SignatureU32 {
fn sig() -> &'static [u8; 4];
}
pub trait CrcU32 {
fn crc(&self) -> [u8; 4];
}
pub trait PayloadCrc
where
Self: PayloadEncoded + PayloadHooks,
{
fn crc(&self, ctx: &mut Self::Context<'_>) -> std::io::Result<ByteBlock> {
let mut hasher = crc32fast::Hasher::new();
hasher.update(self.encoded(ctx)?.as_slice());
Ok(ByteBlock::Len4(hasher.finalize().to_le_bytes()))
}
fn crc_size() -> usize {
4
}
}
pub trait PayloadSignature {
fn sig(&self) -> ByteBlock;
}
pub trait StaticPayloadSignature {
fn ssig() -> ByteBlock;
}
pub trait StaticSize {
fn ssize() -> u64;
}
pub trait Size {
fn size(&self) -> u64;
}
pub trait PayloadSize: PayloadEncoded {
fn size(&self, ctx: &mut Self::Context<'_>) -> std::io::Result<u64> {
Ok(self.encoded(ctx)?.len() as u64)
}
}