Skip to main content

RecordBatch

Struct RecordBatch 

Source
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: i64

Offset of the first record in the batch.

§partition_leader_epoch: i32

Partition leader epoch (KIP-101).

§magic: i8

Format version. Always 2 for v2 batches.

§attributes: i16

Bit-packed flags: compression (bits 0–2), timestamp type (bit 3), transactional (bit 4), control (bit 5).

§last_offset_delta: i32

Difference between the first and last record offsets.

§first_timestamp: i64

Wall-clock timestamp of the first record.

§max_timestamp: i64

Wall-clock timestamp of the record with the highest timestamp.

§producer_id: i64

Producer ID (idempotent / transactional producer).

§producer_epoch: i16

Producer epoch (idempotent / transactional producer).

§base_sequence: i32

First sequence number in the batch (idempotent producer).

§records: Vec<Record>

Records in the batch.

Implementations§

Source§

impl RecordBatch

Source

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.

Source

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.

Source

pub fn uncompressed_encoded_len(&self) -> Result<usize>

Return the exact encoded length when records are written without compression.

Source

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.

Source

pub fn compression(&self) -> Result<Compression>

Compression codec selected by bits 0–2 of attributes.

Source

pub const fn timestamp_type(&self) -> TimestampType

Timestamp type from bit 3 of attributes.

Source

pub const fn is_transactional(&self) -> bool

true if bit 4 of attributes is set.

Source

pub const fn is_control_batch(&self) -> bool

true if bit 5 of attributes is set.

Trait Implementations§

Source§

impl Clone for RecordBatch

Source§

fn clone(&self) -> RecordBatch

Returns a duplicate of the value. Read more
1.0.0 (const: unstable) · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
Source§

impl Debug for RecordBatch

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
Source§

impl Eq for RecordBatch

Source§

impl PartialEq for RecordBatch

Source§

fn eq(&self, other: &RecordBatch) -> bool

Tests for self and other values to be equal, and is used by ==.
1.0.0 (const: unstable) · Source§

fn ne(&self, other: &Rhs) -> bool

Tests for !=. The default implementation is almost always sufficient, and should not be overridden without very good reason.
Source§

impl StructuralPartialEq for RecordBatch

Auto Trait Implementations§

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T> ToOwned for T
where T: Clone,

Source§

type Owned = T

The resulting type after obtaining ownership.
Source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
Source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.