Expand description
Kafka wire-protocol compression codecs.
Kafka uses four codecs on the wire: gzip, snappy, lz4, and zstd. Each codec has specific framing conventions.
- gzip: standard RFC-1952 gzip through
flate2, which uses the pure-Rustminiz_oxidebackend. - snappy: xerial-snappy framing over
snapraw blocks. Kafka does not use the standard Google Snappy stream format. It uses the xerial framing: an 8-byte magic header, two 4-byte version fields, then a sequence ofu32-BElength-prefixed raw snappy chunks. - lz4: LZ4 frame format with magic
0x04 22 4D 18, independent blocks, and 64 KiB block size. These are the defaults ofKafkaLZ4BlockOutputStream. - zstd: plain zstd at compression level 3, which is Kafka’s default.
Each codec is behind a Cargo feature: gzip, snappy, lz4, and zstd.
All of them are enabled by default. If you disable a feature, the API stays
the same, but the call returns
Err(CompressionError::FeatureDisabled) at runtime.
§Compress and decompress a record payload
use krabka_compression::{CompressionType, compress, decompress};
use krabka_units::kibibytes;
let compressed = compress(CompressionType::Lz4, b"order-created")?;
let plain = decompress(CompressionType::Lz4, &compressed, kibibytes(1))?;
assert_eq!(plain.as_ref(), b"order-created");Structs§
- Record
Decompression Policy - Validated limits for decompressing untrusted Kafka record payloads.
Enums§
- Compression
Error - Errors that can occur during compression or decompression.
- Compression
Type - Codec identifier matching the lowest three bits of Kafka’s record-batch attribute byte.
Constants§
- RECORD_
DECOMPRESSION_ HARD_ MAX_ OUTPUT - Fixed security ceiling for a decompressed record payload.
- RECORD_
DECOMPRESSION_ HARD_ MAX_ RATIO - Fixed security ceiling for record decompression expansion.
Functions§
- compress
- Compress
datausing the codec identified byct. - compress_
with_ level - Compress
datausing the codec identified byctat compressionlevel(KIP-390). - decompress
- Decompress
datausing the codec identified byct. Seecompress.