kona_protocol/compression/
traits.rs

1//! Contains the core `Compressor` trait.
2
3use crate::CompressorResult;
4use alloc::vec::Vec;
5
6/// Compressor Writer
7///
8/// A trait that expands the standard library `Write` trait to include
9/// compression-specific methods and return [CompressorResult] instead of
10/// standard library `Result`.
11#[allow(clippy::len_without_is_empty)]
12pub trait CompressorWriter {
13    /// Writes the given data to the compressor.
14    fn write(&mut self, data: &[u8]) -> CompressorResult<usize>;
15
16    /// Flushes the buffer.
17    fn flush(&mut self) -> CompressorResult<()>;
18
19    /// Closes the compressor.
20    fn close(&mut self) -> CompressorResult<()>;
21
22    /// Resets the compressor.
23    fn reset(&mut self);
24
25    /// Returns the length of the compressed data.
26    fn len(&self) -> usize;
27
28    /// Reads the compressed data into the given buffer.
29    /// Returns the number of bytes read.
30    fn read(&mut self, buf: &mut [u8]) -> CompressorResult<usize>;
31}
32
33/// Channel Compressor
34///
35/// A compressor for channels.
36pub trait ChannelCompressor: CompressorWriter {
37    /// Returns the compressed data buffer.
38    fn get_compressed(&self) -> Vec<u8>;
39}