pub struct RecordBatch {
pub base_offset: i64,
pub partition_leader_epoch: i32,
pub magic: i8,
pub attributes: i16,
pub last_offset_delta: i32,
pub first_timestamp: i64,
pub max_timestamp: i64,
pub producer_id: i64,
pub producer_epoch: i16,
pub base_sequence: i32,
pub records: Vec<Record>,
}Expand description
A Kafka record batch (message format v2).
batchLength and crc are not stored — they are derived during encode
and validated during decode.
Fields§
§base_offset: i64Offset of the first record in the batch.
partition_leader_epoch: i32Partition leader epoch (KIP-101).
magic: i8Format version. Always 2 for v2 batches.
attributes: i16Bit-packed flags: compression (bits 0–2), timestamp type (bit 3), transactional (bit 4), control (bit 5).
last_offset_delta: i32Difference between the first and last record offsets.
first_timestamp: i64Wall-clock timestamp of the first record.
max_timestamp: i64Wall-clock timestamp of the record with the highest timestamp.
producer_id: i64Producer ID (idempotent / transactional producer).
producer_epoch: i16Producer epoch (idempotent / transactional producer).
base_sequence: i32First sequence number in the batch (idempotent producer).
records: Vec<Record>Records in the batch.
Implementations§
Source§impl RecordBatch
impl RecordBatch
Sourcepub fn encode(&self, buf: &mut BytesMut) -> Result<()>
pub fn encode(&self, buf: &mut BytesMut) -> Result<()>
Encode this batch into buf, including the 12-byte log overhead,
CRC32C, and any compression dictated by self.attributes.
Sourcepub fn encode_with_compression_level(
&self,
buf: &mut BytesMut,
compression_level: Option<i32>,
) -> Result<()>
pub fn encode_with_compression_level( &self, buf: &mut BytesMut, compression_level: Option<i32>, ) -> Result<()>
Encode this batch, passing an optional codec-specific compression level.
Sourcepub fn uncompressed_encoded_len(&self) -> Result<usize>
pub fn uncompressed_encoded_len(&self) -> Result<usize>
Return the exact encoded length when records are written without compression.
Sourcepub fn decode(buf: &mut Bytes) -> Result<Self>
pub fn decode(buf: &mut Bytes) -> Result<Self>
Decode one batch from buf. Validates CRC32C, decompresses if needed,
and rejects a record_count above super::MAX_RECORDS_PER_BATCH.
Sourcepub fn compression(&self) -> Result<Compression>
pub fn compression(&self) -> Result<Compression>
Compression codec selected by bits 0–2 of attributes.
Sourcepub const fn timestamp_type(&self) -> TimestampType
pub const fn timestamp_type(&self) -> TimestampType
Timestamp type from bit 3 of attributes.
Sourcepub const fn is_transactional(&self) -> bool
pub const fn is_transactional(&self) -> bool
true if bit 4 of attributes is set.
Sourcepub const fn is_control_batch(&self) -> bool
pub const fn is_control_batch(&self) -> bool
true if bit 5 of attributes is set.
Trait Implementations§
Source§impl Clone for RecordBatch
impl Clone for RecordBatch
Source§fn clone(&self) -> RecordBatch
fn clone(&self) -> RecordBatch
1.0.0 (const: unstable) · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
source. Read moreSource§impl Debug for RecordBatch
impl Debug for RecordBatch
impl Eq for RecordBatch
Source§impl PartialEq for RecordBatch
impl PartialEq for RecordBatch
Source§fn eq(&self, other: &RecordBatch) -> bool
fn eq(&self, other: &RecordBatch) -> bool
self and other values to be equal, and is used by ==.