Skip to main content

photon_protocol/ports/
compress.rs

1use bytes::BytesMut;
2
3pub trait Compressor: Send + Sync + Clone + 'static {
4    fn compress(&self, input: &[u8], output: &mut BytesMut) -> Result<(), CompressionError>;
5
6    fn decompress(&self, input: &[u8], output: &mut BytesMut) -> Result<(), CompressionError>;
7
8    /// Stable identifier written to WAL record headers.
9    /// Must not change across versions for a given algorithm.
10    fn name(&self) -> &'static str;
11}
12
13#[derive(Debug, thiserror::Error)]
14pub enum CompressionError {
15    #[error("output buffer too small (needed {needed}, available {available})")]
16    BufferTooSmall { needed: usize, available: usize },
17
18    #[error("corrupt payload for compressor {compressor_name:?}")]
19    CorruptPayload { compressor_name: String },
20
21    #[error(transparent)]
22    Unknown(#[from] anyhow::Error),
23}