Expand description
Apache Kafka legacy (v0/v1) MessageSet codec.
This crate also bridges to and from the v2 RecordBatch types in
[krabka_protocol].
See the Kafka protocol docs for the wire layout that this crate
implements. v0 carries no per-message timestamp. v1 adds one i64
timestamp per message (KIP-32). Both versions signal compression in
the low 3 bits of the per-message attributes byte. The compressed
payload is a single outer message whose value is a nested,
uncompressed MessageSet.
§Quick tour
Message/Magic: per-message wire format, with a CRC and the message fields.ParsedRecord: cross-format view of a single offset-tagged record.decode_message_set/encode_flat_message_set/encode_compressed_message_set: top-level codec.v2_to_legacy/legacy_to_v2: bridge to and fromkrabka_protocol::records::RecordBatch. Use these from the Fetch handler for down-conversion, and from the Produce handler for up-conversion.
§Encode and decode a v1 MessageSet
use {
bytes::{Bytes, BytesMut},
krabka_ids::Offset,
krabka_records_legacy::{Magic, ParsedRecord, decode_message_set, encode_flat_message_set},
};
let records = vec![ParsedRecord {
offset: 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())?;
assert2::assert!((decoded[0].offset) == (Offset(42)));Modules§
- attrs
- Bit layout of the legacy
attributesbyte.
Structs§
- Message
- Owned legacy message, decoded after the frame parse.
- Parsed
Record - A single decoded
MessageSetentry.
Enums§
- Legacy
Records Error - Magic
- Magic byte, that is, the legacy message-format version: 0 or 1.
Functions§
- attrs_
with_ compression - Panics
- compression_
from_ attrs - Map a v0/v1 compression code to a [
CompressionType]. - decode_
message_ set - Decode a flat, uncompressed
MessageSetfrombuf. - decode_
message_ set_ with_ policy - Decode a legacy
MessageSetwith explicit decompression limits. - encode_
compressed_ message_ set - Encode a
MessageSetwrapped in a single compressed outer message. - encode_
flat_ message_ set - Encode a flat
MessageSetof magicmagicintobuf. - legacy_
to_ v2 - Up-convert a v0/v1
MessageSetto a v2 [RecordBatch]. - legacy_
to_ v2_ with_ policy - Up-convert a legacy
MessageSetusing explicit decompression limits. - parsed_
from_ v2 - Iterate the v2 batch’s records and drop control batches entirely.
- v2_
to_ legacy - Down-convert a v2 [
RecordBatch] to v0/v1MessageSetbytes.