Skip to main content

Crate crabka_compression

Crate crabka_compression 

Source
Expand description

Kafka wire-protocol compression codecs.

Kafka uses four codecs on the wire — gzip, snappy, lz4, zstd — each with specific framing conventions:

  • gzip: standard RFC-1952 gzip via flate2 (pure-Rust miniz_oxide backend).
  • snappy: xerial-snappy framing over snap raw blocks. Kafka does not use the standard Google Snappy stream format; it uses the xerial framing (8-byte magic header, two 4-byte version fields, then a sequence of u32-BE length-prefixed raw snappy chunks).
  • lz4: LZ4 frame format (magic 0x04 22 4D 18) with independent blocks and 64 KiB block size, matching KafkaLZ4BlockOutputStream’s defaults.
  • zstd: plain zstd at compression level 3 (Kafka’s default).

Each codec is behind a Cargo feature (gzip, snappy, lz4, zstd), all enabled by default. Disabling a feature leaves the API stable but returns Err(CompressionError::FeatureDisabled) at runtime.

§Compress and decompress a record payload

use crabka_compression::{CompressionType, compress, decompress};

let compressed = compress(CompressionType::Lz4, b"order-created")?;
let plain = decompress(CompressionType::Lz4, &compressed, 1024)?;
assert_eq!(plain.as_ref(), b"order-created");

Enums§

CompressionError
Errors that can occur during compression or decompression.
CompressionType
Codec identifier matching the lowest three bits of Kafka’s record-batch attribute byte.

Functions§

compress
Compress data using the codec identified by ct.
decompress
Decompress data using the codec identified by ct. See compress.