crabka-compression
Kafka wire-protocol compression codecs for Rust.
Part of Crabka, a Rust implementation of Apache Kafka-compatible infrastructure and clients.
Overview
crabka-compression implements the compression formats Apache Kafka uses in
record batches. It is a small, I/O-free crate used by crabka-protocol, the
producer, and storage code whenever bytes must match Kafka's wire framing.
The crate exposes a stable CompressionType enum that maps to Kafka's record
batch attribute bits and compress/decompress helpers for payload bytes.
Codecs
gzip- RFC 1952 gzip streams.snappy- Kafka's xerial-snappy framing, not Google's Snappy stream format.lz4- LZ4 frame format with independent blocks and 64 KiB block size.zstd- plain zstd frame at level 3.none- pass-through payloads.
Install
For workspace development, use the path dependency from this repository.
Usage
Compress and decompress a Kafka payload:
use ;
let compressed = compress?;
let plain = decompress?;
assert_eq!;
# Ok::
decompress requires a caller-provided max_output limit to guard against
decompression bombs.
Cargo Features
All codecs are enabled by default. Disable defaults and opt into only the codecs you need:
= { = "0.3.8", = false, = ["gzip", "zstd"] }
Calling a disabled codec returns CompressionError::FeatureDisabled.
Documentation
License
Apache-2.0. Derivative work of Apache Kafka; see NOTICE.