photon_protocol/ports/
compress.rs1use 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 fn name(&self) -> &'static str;
11}
12
13#[non_exhaustive]
14#[derive(Debug, thiserror::Error)]
15pub enum CompressionError {
16 #[error("output buffer too small (needed {needed}, available {available})")]
17 BufferTooSmall { needed: usize, available: usize },
18
19 #[error("corrupt payload for compressor {compressor_name:?}")]
20 CorruptPayload { compressor_name: String },
21
22 #[error("internal error: {0}")]
23 Internal(String),
24}