Skip to main content

Crate crabka_records_legacy

Crate crabka_records_legacy 

Source
Expand description

Apache Kafka legacy (v0/v1) MessageSet codec, with bridges to and from the v2 RecordBatch types in crabka_protocol.

See the Kafka protocol docs for the wire layout this crate implements. v0 carries no per-message timestamp; v1 adds an i64 timestamp per message (KIP-32). Compression in both is signalled in the low 3 bits of the per-message attributes byte, with the compressed payload appearing as a single outer message whose value is a nested (uncompressed) MessageSet.

§Quick tour

§Encode and decode a v1 MessageSet

use bytes::{Bytes, BytesMut};
use crabka_records_legacy::{Magic, ParsedRecord, decode_message_set, encode_flat_message_set};

let records = vec![ParsedRecord {
    offset: 42,
    timestamp: Some(1_713_000_000_000),
    key: Some(Bytes::from_static(b"order-42")),
    value: Some(Bytes::from_static(b"created")),
}];

let mut buf = BytesMut::new();
encode_flat_message_set(records, Magic::V1, &mut buf);
let decoded = decode_message_set(&mut &buf[..], buf.len())?;
assert_eq!(decoded[0].offset, 42);

Modules§

attrs
Bit layout of the legacy attributes byte.

Structs§

Message
Owned, decoded legacy message (post-frame parse).
ParsedRecord
A single decoded MessageSet entry: the offset-tagged payload of one logical record after compression unwrapping.

Enums§

LegacyRecordsError
Magic
Magic byte (i.e. legacy message format version) — 0 or 1.

Functions§

attrs_with_compression
compression_from_attrs
Map a v0/v1 compression-code (low 3 bits of attributes) to a CompressionType.
decode_message_set
Decode a flat (uncompressed) MessageSet from buf, expecting it to consume exactly set_size_bytes bytes from the buffer. Compressed wrapper messages encountered at top level are unwrapped recursively once — nested compression (a compressed wrapper inside a compressed wrapper) is rejected.
encode_compressed_message_set
Encode a MessageSet wrapped in a single compressed outer message. The inner set is uncompressed and contains one message per record, laid out per KIP-32 conventions (v1 inner offsets relative 0..N-1).
encode_flat_message_set
Encode a flat MessageSet (one outer message per record) of magic magic into buf. Useful when emitting an uncompressed batch.
legacy_to_v2
Up-convert a v0/v1 MessageSet to a v2 RecordBatch suitable for the log write path.
parsed_from_v2
Iterate the v2 batch’s records, dropping control batches entirely.
v2_to_legacy
Down-convert a v2 RecordBatch to v0/v1 MessageSet bytes.