Skip to main content

Module tier_compressor

Module tier_compressor 

Source
Expand description

Cache-entry compression for tiered L2+ cache layers.

Large cache tiers (L2 memory or disk) can benefit from compressing stored values to reduce footprint. This module provides a pure-Rust, zero- dependency LZ77-style byte-pair run-length codec suitable for media metadata and moderate-size frame buffers.

§Design

TierCompressor wraps a configurable compression level and exposes a symmetric [compress] / [decompress] pair. The codec is a simplified LZ77 variant:

  • The input stream is divided into 256-byte look-ahead windows.
  • Literal bytes are emitted as [0x00, byte].
  • Back-references (offset, length) with length >= 3 are emitted as [0x01, offset_lo, offset_hi, length] (offset = distance back into the output buffer, length = match length).
  • A header [0xCA, 0xCE, 0x00] + 4-byte LE original length is prepended so decompression can pre-allocate and validate.

The codec is designed for correctness and minimal overhead, not maximum compression ratio.

§Compression levels

LevelLook-ahead windowSearch depth
06416
112832
225664
3512128

Higher levels produce smaller output but take more CPU time.

§Example

use oximedia_cache::tier_compressor::TierCompressor;

let c = TierCompressor::new(1);
let original = b"hello hello hello world".to_vec();
let compressed = c.compress(&original).expect("compress");
let restored = c.decompress(&compressed).expect("decompress");
assert_eq!(restored, original);

Structs§

TierCompressor
Symmetric compressor/decompressor for cache tier entries.

Enums§

CompressorError
Errors produced by TierCompressor.