photon-protocol 0.1.0

Internal codec and compression traits for Photon
Documentation
use bytes::BytesMut;

pub trait Compressor: Send + Sync + Clone + 'static {
    fn compress(&self, input: &[u8], output: &mut BytesMut) -> Result<(), CompressionError>;

    fn decompress(&self, input: &[u8], output: &mut BytesMut) -> Result<(), CompressionError>;

    /// Stable identifier written to WAL record headers.
    /// Must not change across versions for a given algorithm.
    fn name(&self) -> &'static str;
}

#[derive(Debug, thiserror::Error)]
pub enum CompressionError {
    #[error("output buffer too small (needed {needed}, available {available})")]
    BufferTooSmall { needed: usize, available: usize },

    #[error("corrupt payload for compressor {compressor_name:?}")]
    CorruptPayload { compressor_name: String },

    #[error(transparent)]
    Unknown(#[from] anyhow::Error),
}