1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39
//! Provides compression utilities for encoding records.
//!
//! This module has implementations of gzip, Snappy, as well as a noop compression format that
//! allows encoding and decoding records into a [`Record`](crate::records::Record).
use crate::protocol::buf::{ByteBuf, ByteBufMut};
use crate::protocol::{DecodeError, EncodeError};
mod gzip;
mod lz4;
mod none;
mod snappy;
mod zstd;
pub use gzip::Gzip;
pub use lz4::Lz4;
pub use none::None;
pub use snappy::Snappy;
pub use zstd::Zstd;
/// A trait for record compression algorithms.
pub trait Compressor<B: ByteBufMut> {
/// Target buffer type for compression.
type BufMut: ByteBufMut;
/// Compresses into provided [`ByteBufMut`], with records encoded by `F` into `R`.
fn compress<R, F>(buf: &mut B, f: F) -> Result<R, EncodeError>
where
F: FnOnce(&mut Self::BufMut) -> Result<R, EncodeError>;
}
/// A trait for record decompression algorithms.
pub trait Decompressor<B: ByteBuf> {
/// Target buffer type for decompression.
type Buf: ByteBuf;
/// Decompress records from `B` mapped using `F` into `R`.
fn decompress<R, F>(buf: &mut B, f: F) -> Result<R, DecodeError>
where
F: FnOnce(&mut Self::Buf) -> Result<R, DecodeError>;
}