pub struct ScpStorageCompressionPipeline { /* private fields */ }Expand description
A configurable multi-stage data compression pipeline.
Each stage can independently apply an algorithm (RLE, LZ77, Delta, XOR) to the running data buffer, or be skipped based on size thresholds.
§Thread safety
This type is Send + Sync. Statistics are guarded by a parking_lot::Mutex.
Implementations§
Source§impl ScpStorageCompressionPipeline
impl ScpStorageCompressionPipeline
Sourcepub fn new(config: ScpPipelineConfig) -> Self
pub fn new(config: ScpPipelineConfig) -> Self
Create a new pipeline with the given configuration.
Returns ScpPipelineError::InvalidConfiguration if any stage
has an XOR algorithm with an empty key.
Sourcepub fn compress(&self, data: &[u8]) -> Result<CompressedBlock, ScpPipelineError>
pub fn compress(&self, data: &[u8]) -> Result<CompressedBlock, ScpPipelineError>
Compress data through all configured stages in order.
Stages that are disabled or whose min_size_bytes is not met are
transparently skipped. When enable_checksum is set, an 8-byte
FNV-1a-64 checksum is appended to the output payload.
Sourcepub fn decompress(
&self,
block: &CompressedBlock,
) -> Result<Vec<u8>, ScpPipelineError>
pub fn decompress( &self, block: &CompressedBlock, ) -> Result<Vec<u8>, ScpPipelineError>
Decompress a CompressedBlock produced by this pipeline (or any
pipeline with identical stage configuration).
Stages are applied in reverse order using the stages_applied
list embedded in the block.
Sourcepub fn compress_with_stages(
&self,
data: &[u8],
stages: &[CompressionStage],
) -> Result<CompressedBlock, ScpPipelineError>
pub fn compress_with_stages( &self, data: &[u8], stages: &[CompressionStage], ) -> Result<CompressedBlock, ScpPipelineError>
Compress data using a custom set of stages instead of those in
the pipeline’s configuration.
The max_input_size and enable_checksum settings from the
pipeline configuration still apply.
Sourcepub fn best_algorithm(&self, data: &[u8]) -> ScpCompressionAlgorithm
pub fn best_algorithm(&self, data: &[u8]) -> ScpCompressionAlgorithm
Heuristically determine the best single-stage algorithm for data
by trying None, Rle, and Lz77 on the first 1024 bytes.
Returns the algorithm that yields the best compression ratio.
Sourcepub fn stats(&self) -> ScpPipelineStats
pub fn stats(&self) -> ScpPipelineStats
Return a snapshot of the current pipeline statistics.
Auto Trait Implementations§
impl !RefUnwindSafe for ScpStorageCompressionPipeline
impl !UnwindSafe for ScpStorageCompressionPipeline
impl Freeze for ScpStorageCompressionPipeline
impl Send for ScpStorageCompressionPipeline
impl Sync for ScpStorageCompressionPipeline
impl Unpin for ScpStorageCompressionPipeline
impl UnsafeUnpin for ScpStorageCompressionPipeline
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
impl<ST, DT> CastableFrom<ST, Initialized, Initialized> for DT
impl<ST, DT> CastableFrom<ST, Uninit, Uninit> for DT
Source§impl<T> Instrument for T
impl<T> Instrument for T
Source§fn instrument(self, span: Span) -> Instrumented<Self>
fn instrument(self, span: Span) -> Instrumented<Self>
Source§fn in_current_span(self) -> Instrumented<Self>
fn in_current_span(self) -> Instrumented<Self>
Source§impl<T> IntoEither for T
impl<T> IntoEither for T
Source§fn into_either(self, into_left: bool) -> Either<Self, Self>
fn into_either(self, into_left: bool) -> Either<Self, Self>
self into a Left variant of Either<Self, Self>
if into_left is true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read moreSource§fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
self into a Left variant of Either<Self, Self>
if into_left(&self) returns true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read more