pub struct SkippableFrame { /* private fields */ }lsm only.Expand description
A typed skippable-frame value.
Construct via SkippableFrame::new (validates the variant bound
and payload size up front) or SkippableFrame::decode_from.
Round-trip a frame via SkippableFrame::encode_into.
Implementations§
Source§impl SkippableFrame
impl SkippableFrame
Sourcepub fn new(
magic_variant: u8,
payload: Vec<u8>,
) -> Result<Self, SkippableFrameError>
pub fn new( magic_variant: u8, payload: Vec<u8>, ) -> Result<Self, SkippableFrameError>
Build a SkippableFrame from its components. Validates:
magic_variant <= 15(SkippableFrameError::InvalidMagicVariant).payload.len() <= u32::MAX as usize(SkippableFrameError::PayloadTooLarge) — unreachable on 32-bit and smaller targets but enforced uniformly so 64-bit callers cannot smuggle through an overlong payload.
Sourcepub fn magic_variant(&self) -> u8
pub fn magic_variant(&self) -> u8
The 4-bit variant nibble. Combined with SKIPPABLE_MAGIC_START
to form the on-wire magic number (magic = START + variant).
Sourcepub fn magic_number(&self) -> u32
pub fn magic_number(&self) -> u32
Full 32-bit magic number this frame serialises with.
Sourcepub fn payload(&self) -> &[u8] ⓘ
pub fn payload(&self) -> &[u8] ⓘ
Payload bytes carried by the frame (without the 8-byte header).
Sourcepub fn into_payload(self) -> Vec<u8> ⓘ
pub fn into_payload(self) -> Vec<u8> ⓘ
Move the payload out, consuming the frame.
Sourcepub fn serialized_size(&self) -> usize
pub fn serialized_size(&self) -> usize
Total serialised size of this frame on the wire:
payload.len() + 8 (8 = 4-byte magic + 4-byte length).
Sourcepub fn encode_into<W: Write>(&self, writer: &mut W) -> Result<(), Error>
pub fn encode_into<W: Write>(&self, writer: &mut W) -> Result<(), Error>
Serialise this frame into writer. Writes
serialized_size() bytes total: 4-byte magic LE,
4-byte length LE, payload bytes.
Sourcepub fn decode_from<R: Read>(
reader: &mut R,
) -> Result<Self, DecodeSkippableFrameError>
pub fn decode_from<R: Read>( reader: &mut R, ) -> Result<Self, DecodeSkippableFrameError>
Read one skippable frame from reader. Consumes
4-byte magic + 4-byte length + length payload bytes. The
caller is responsible for positioning the reader at a frame
boundary; this method does not scan past unknown content.
Three layers of protection against crafted-length DoS:
-
Validates that
lengthis representable on the target pointer width (length + SKIPPABLE_HEADER_SIZEmust not overflowusize). On 32-bit targets a wirelengthnearu32::MAXwould otherwise overflowserialized_size()andwrite_skippable_frame_to. ReturnsDecodeSkippableFrameError::PayloadTooLargeup front. -
Reserves the address space via
Vec::try_reserve_exact, converting alloc-failure into typedDecodeSkippableFrameError::AllocationFailedinstead of process abort. -
Reads the payload in fixed-size chunks via a stack scratch buffer, so the OS only commits pages for bytes the reader actually delivers. A crafted
lengthnearu32::MAXon a reader that terminates early surfaces asDecodeSkippableFrameError::Payloadwithout ever committing the full allocation — on OSes with memory overcommit (Linux default) where step 2 would otherwise succeed for any nominal size, this is what makes the “no abort on huge length” guarantee actually reliable.
Callers handling untrusted streams should additionally cap
the acceptable payload size at the application layer; this
method itself imposes no upper bound beyond the wire-format
u32::MAX plus target-representability.
Trait Implementations§
Source§impl Clone for SkippableFrame
impl Clone for SkippableFrame
Source§fn clone(&self) -> SkippableFrame
fn clone(&self) -> SkippableFrame
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 SkippableFrame
impl Debug for SkippableFrame
Source§impl PartialEq for SkippableFrame
impl PartialEq for SkippableFrame
Source§fn eq(&self, other: &SkippableFrame) -> bool
fn eq(&self, other: &SkippableFrame) -> bool
self and other values to be equal, and is used by ==.