pub enum RecordsPayload {
V2(Vec<RecordBatch>),
Raw(Bytes),
Legacy(Bytes),
}Expand description
Owned form of a records-field payload.
Variants§
V2(Vec<RecordBatch>)
Zero or more parsed v2 batches (the records field is a sequence).
Raw(Bytes)
Verbatim, already-wire-format v2 bytes (one or more batches), forwarded without parsing. Produced by the fetch pass-through path.
Legacy(Bytes)
Opaque pre-v2 bytes (v0/v1 MessageSet). Decode with
crabka_records_legacy::decode_message_set.
Implementations§
Source§impl RecordsPayload
impl RecordsPayload
Sourcepub fn from_bytes(bytes: Bytes) -> Result<Self, RecordsError>
pub fn from_bytes(bytes: Bytes) -> Result<Self, RecordsError>
Construct from raw records-field bytes. When the bytes look like v2, decode every batch in the field; otherwise keep as opaque legacy.
Sourcepub fn payload_len(&self) -> usize
pub fn payload_len(&self) -> usize
Wire size of the records-field bytes (no outer length prefix).
Sourcepub fn encode_to<B: BufMut>(&self, buf: &mut B) -> Result<(), RecordsError>
pub fn encode_to<B: BufMut>(&self, buf: &mut B) -> Result<(), RecordsError>
Write the payload bytes into buf (caller owns the outer framing).
Sourcepub fn as_v2(&self) -> Option<&[RecordBatch]>
pub fn as_v2(&self) -> Option<&[RecordBatch]>
Borrow the parsed v2 batches, if this is a parsed V2 payload.
Returns None for Raw (intentionally unparsed) and Legacy.
Sourcepub fn as_legacy(&self) -> Option<&Bytes>
pub fn as_legacy(&self) -> Option<&Bytes>
Borrow as raw legacy bytes, if that’s what this payload is.
Sourcepub fn from_fetch_bytes(bytes: Bytes) -> Result<Self, RecordsError>
pub fn from_fetch_bytes(bytes: Bytes) -> Result<Self, RecordsError>
Decode a response-side records field, tolerating a truncated
trailing batch. Kafka returns a partial final RecordBatch when a
partition’s fetch byte budget is hit mid-batch; the JVM consumer stops
at the first incomplete batch and re-fetches it from the next offset.
We mirror that: decode every complete batch, and on the first
HeaderTooShort / BodyTooShort stop and drop the remainder. A
corrupt complete batch (bad CRC/magic/content) still errors — leniency
forgives truncation only. Strict from_bytes is
retained for Produce-request validation.
Only HeaderTooShort/BodyTooShort are treated as truncation; a genuinely
invalid batch_length (RecordParse) is corruption and still errors —
legitimate Kafka truncation always preserves a valid batch_length prefix,
so it can only manifest as the too-short variants.
Sourcepub fn decode_lenient<B: Buf>(
buf: &mut B,
_version: i16,
) -> Result<Self, ProtocolError>
pub fn decode_lenient<B: Buf>( buf: &mut B, _version: i16, ) -> Result<Self, ProtocolError>
Decode-shaped lenient entry point the generated codec calls for
records fields in response messages. Consumes the whole sliced
field buffer (the caller has already framed it) and parses leniently
via from_fetch_bytes.
Trait Implementations§
Source§impl Clone for RecordsPayload
impl Clone for RecordsPayload
Source§fn clone(&self) -> RecordsPayload
fn clone(&self) -> RecordsPayload
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 RecordsPayload
impl Debug for RecordsPayload
Source§impl Decode<'_> for RecordsPayload
impl Decode<'_> for RecordsPayload
Source§impl Default for RecordsPayload
impl Default for RecordsPayload
Source§impl Encode for RecordsPayload
impl Encode for RecordsPayload
impl Eq for RecordsPayload
Source§impl From<RecordBatch> for RecordsPayload
impl From<RecordBatch> for RecordsPayload
Source§fn from(rb: RecordBatch) -> Self
fn from(rb: RecordBatch) -> Self
Source§impl From<Vec<RecordBatch>> for RecordsPayload
impl From<Vec<RecordBatch>> for RecordsPayload
Source§fn from(v: Vec<RecordBatch>) -> Self
fn from(v: Vec<RecordBatch>) -> Self
Source§impl PartialEq for RecordsPayload
impl PartialEq for RecordsPayload
Source§fn eq(&self, other: &RecordsPayload) -> bool
fn eq(&self, other: &RecordsPayload) -> bool
self and other values to be equal, and is used by ==.