pub enum RecordsPayload {
V2(Vec<RecordBatch>),
Raw(Bytes),
Legacy(Bytes),
FileRegions(Vec<FileRegion>),
}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 wire-format v2 bytes, one or more batches, forwarded without parsing. The fetch pass-through path produces this variant.
Legacy(Bytes)
Opaque pre-v2 bytes, a v0 or v1 MessageSet. Decode them with
krabka_records_legacy::decode_message_set.
FileRegions(Vec<FileRegion>)
Zero-copy fetch (Increments D + E): the records run stays in segment
.log files. The broker sendfile(2)s it straight to a plaintext
socket and never materializes it in userspace. There is one
crate::records::FileRegion per contributing segment. encode_to
falls back to pread + put_slice on TLS and non-sendfile platforms,
and for encoded_len agreement. This variant is gated on the SENDFILE
alias (Linux + Apple + FreeBSD/DragonFly) because it only exists to feed
the sendfile drainer. On Windows the fallback pread path runs.
Implementations§
Source§impl RecordsPayload
impl RecordsPayload
Sourcepub fn from_bytes(bytes: Bytes) -> Result<Self, RecordsError>
pub fn from_bytes(bytes: Bytes) -> Result<Self, RecordsError>
Constructs a payload from raw records-field bytes.
When the bytes look like v2, this function decodes every batch in the field. If they do not, it keeps the bytes as opaque legacy bytes.
§Errors
Returns the underlying protocol error when input is truncated, contains an invalid length or tag, or cannot be encoded for the selected version.
Sourcepub fn from_bytes_with_policy(
bytes: Bytes,
policy: RecordDecompressionPolicy,
) -> Result<Self, RecordsError>
pub fn from_bytes_with_policy( bytes: Bytes, policy: RecordDecompressionPolicy, ) -> Result<Self, RecordsError>
Constructs a payload from raw records bytes with explicit decompression limits.
§Errors
Returns the underlying records error for malformed, truncated, corrupt, or over-limit v2 input.
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>
Writes the payload bytes into buf.
The caller owns the outer framing.
For FileRegions this is the fallback path, used on TLS, on
non-Linux platforms, and for encoded_len agreement. It preads
each region out of the segment file and copies it into buf. The
broker’s zero-copy sendfile path never calls this method. That path
consumes the FileRegions directly.
§Errors
Returns the underlying protocol error when input is truncated, contains an invalid length or tag, or cannot be encoded for the selected version.
Sourcepub fn as_v2(&self) -> Option<&[RecordBatch]>
pub fn as_v2(&self) -> Option<&[RecordBatch]>
Borrows the parsed v2 batches, if this is a parsed V2 payload.
Returns None for Raw, which is intentionally unparsed, for
Legacy, and for FileRegions, which is deliberately never
materialized.
Sourcepub fn as_legacy(&self) -> Option<&Bytes>
pub fn as_legacy(&self) -> Option<&Bytes>
Borrows the raw legacy bytes, if this payload is Legacy.
Sourcepub fn from_fetch_bytes(bytes: Bytes) -> Result<Self, RecordsError>
pub fn from_fetch_bytes(bytes: Bytes) -> Result<Self, RecordsError>
Decodes a response-side records field and tolerates a truncated trailing batch.
Kafka returns a partial final RecordBatch when a partition hits its
fetch byte budget mid-batch. The JVM consumer stops at the first
incomplete batch and re-fetches it from the next offset. This function
does the same: it decodes every complete batch, then stops at the first
HeaderTooShort or BodyTooShort and drops the remainder. A complete
batch that is corrupt in its CRC, magic byte, or content still returns
an error, because the leniency forgives truncation only.
Produce-request validation keeps the strict
from_bytes.
This function treats only HeaderTooShort and BodyTooShort as
truncation. An invalid batch_length gives RecordParse, which is
corruption and still returns an error. Kafka truncation always keeps a
valid batch_length prefix, so truncation can appear only as the two
too-short variants.
§Errors
Returns the underlying protocol error when input is truncated, contains an invalid length or tag, or cannot be encoded for the selected version.
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>
Lenient Decode-shaped entry point for records fields in response
messages.
The generated codec calls this method. It consumes the whole sliced
field buffer, which the caller has already framed, and parses the bytes
leniently through from_fetch_bytes.
§Errors
Returns the underlying protocol error when input is truncated, contains an invalid length or tag, or cannot be encoded for the selected version.
Trait Implementations§
Source§impl Clone for RecordsPayload
impl Clone for RecordsPayload
Source§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
impl StructuralPartialEq for RecordsPayload
Auto Trait Implementations§
impl !Freeze for RecordsPayload
impl RefUnwindSafe for RecordsPayload
impl Send for RecordsPayload
impl Sync for RecordsPayload
impl Unpin for RecordsPayload
impl UnsafeUnpin for RecordsPayload
impl UnwindSafe for RecordsPayload
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
impl<ST, DT> CastableFrom<ST, Initialized, Initialized> for DT
impl<ST, DT> CastableFrom<ST, Uninit, Uninit> for DT
Source§impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
Source§impl<T> Paint for Twhere
T: ?Sized,
impl<T> Paint for Twhere
T: ?Sized,
Source§fn fg(&self, value: Color) -> Painted<&T>
fn fg(&self, value: Color) -> Painted<&T>
Returns a styled value derived from self with the foreground set to
value.
This method should be used rarely. Instead, prefer to use color-specific
builder methods like red() and
green(), which have the same functionality but are
pithier.
§Example
Set foreground color to white using fg():
use yansi::{Paint, Color};
painted.fg(Color::White);Set foreground color to white using white().
use yansi::Paint;
painted.white();Source§fn bright_black(&self) -> Painted<&T>
fn bright_black(&self) -> Painted<&T>
Source§fn bright_red(&self) -> Painted<&T>
fn bright_red(&self) -> Painted<&T>
Source§fn bright_green(&self) -> Painted<&T>
fn bright_green(&self) -> Painted<&T>
Source§fn bright_yellow(&self) -> Painted<&T>
fn bright_yellow(&self) -> Painted<&T>
Source§fn bright_blue(&self) -> Painted<&T>
fn bright_blue(&self) -> Painted<&T>
Source§fn bright_magenta(&self) -> Painted<&T>
fn bright_magenta(&self) -> Painted<&T>
Source§fn bright_cyan(&self) -> Painted<&T>
fn bright_cyan(&self) -> Painted<&T>
Source§fn bright_white(&self) -> Painted<&T>
fn bright_white(&self) -> Painted<&T>
Source§fn bg(&self, value: Color) -> Painted<&T>
fn bg(&self, value: Color) -> Painted<&T>
Returns a styled value derived from self with the background set to
value.
This method should be used rarely. Instead, prefer to use color-specific
builder methods like on_red() and
on_green(), which have the same functionality but
are pithier.
§Example
Set background color to red using fg():
use yansi::{Paint, Color};
painted.bg(Color::Red);Set background color to red using on_red().
use yansi::Paint;
painted.on_red();Source§fn on_primary(&self) -> Painted<&T>
fn on_primary(&self) -> Painted<&T>
Source§fn on_magenta(&self) -> Painted<&T>
fn on_magenta(&self) -> Painted<&T>
Source§fn on_bright_black(&self) -> Painted<&T>
fn on_bright_black(&self) -> Painted<&T>
Source§fn on_bright_red(&self) -> Painted<&T>
fn on_bright_red(&self) -> Painted<&T>
Source§fn on_bright_green(&self) -> Painted<&T>
fn on_bright_green(&self) -> Painted<&T>
Source§fn on_bright_yellow(&self) -> Painted<&T>
fn on_bright_yellow(&self) -> Painted<&T>
Source§fn on_bright_blue(&self) -> Painted<&T>
fn on_bright_blue(&self) -> Painted<&T>
Source§fn on_bright_magenta(&self) -> Painted<&T>
fn on_bright_magenta(&self) -> Painted<&T>
Source§fn on_bright_cyan(&self) -> Painted<&T>
fn on_bright_cyan(&self) -> Painted<&T>
Source§fn on_bright_white(&self) -> Painted<&T>
fn on_bright_white(&self) -> Painted<&T>
Source§fn attr(&self, value: Attribute) -> Painted<&T>
fn attr(&self, value: Attribute) -> Painted<&T>
Enables the styling Attribute value.
This method should be used rarely. Instead, prefer to use
attribute-specific builder methods like bold() and
underline(), which have the same functionality
but are pithier.
§Example
Make text bold using attr():
use yansi::{Paint, Attribute};
painted.attr(Attribute::Bold);Make text bold using using bold().
use yansi::Paint;
painted.bold();Source§fn rapid_blink(&self) -> Painted<&T>
fn rapid_blink(&self) -> Painted<&T>
Source§fn quirk(&self, value: Quirk) -> Painted<&T>
fn quirk(&self, value: Quirk) -> Painted<&T>
Enables the yansi Quirk value.
This method should be used rarely. Instead, prefer to use quirk-specific
builder methods like mask() and
wrap(), which have the same functionality but are
pithier.
§Example
Enable wrapping using .quirk():
use yansi::{Paint, Quirk};
painted.quirk(Quirk::Wrap);Enable wrapping using wrap().
use yansi::Paint;
painted.wrap();Source§fn clear(&self) -> Painted<&T>
👎Deprecated since 1.0.1: renamed to resetting() due to conflicts with Vec::clear().
The clear() method will be removed in a future release.
fn clear(&self) -> Painted<&T>
renamed to resetting() due to conflicts with Vec::clear().
The clear() method will be removed in a future release.
Source§fn whenever(&self, value: Condition) -> Painted<&T>
fn whenever(&self, value: Condition) -> Painted<&T>
Conditionally enable styling based on whether the Condition value
applies. Replaces any previous condition.
See the crate level docs for more details.
§Example
Enable styling painted only when both stdout and stderr are TTYs:
use yansi::{Paint, Condition};
painted.red().on_yellow().whenever(Condition::STDOUTERR_ARE_TTY);