Skip to main content

ChunkAssembler

Struct ChunkAssembler 

Source
pub struct ChunkAssembler { /* private fields */ }
Expand description

Stateful inbound chunk reassembler (§5.3): feed inbound bytes, get back each complete Message as soon as its last chunk arrives.

Maintains per-chunk_stream_id state, so multiple chunk streams may be interleaved on the same connection (as the wire format requires) and are each reassembled independently.

Implementations§

Source§

impl ChunkAssembler

Source

pub fn new() -> Self

New assembler, chunk size at the §5.3 default (128 bytes).

Source

pub fn with_max_in_progress_bytes(self, max_in_progress_bytes: usize) -> Self

Set the ceiling on total payload bytes buffered across all in-progress messages (#1108/RTMP-W1); see DEFAULT_MAX_IN_PROGRESS_BYTES for the default and its rationale.

Source

pub fn with_chunk_size(self, n: u32) -> Self

Builder form of Self::set_chunk_size (same clamping rules).

Source

pub fn set_chunk_size(&mut self, n: u32)

Update the chunk size in effect for subsequent chunks (called on receipt of a Set Chunk Size protocol control message, §5.4.1). Per private/specs-verified/rtmp/rtmp-runtime/rtmp.md §3’s transcription of §5.4.1 (“Default max chunk size is 128; SHOULD be ≥ 128, MUST be ≥ 1”), 128 is only a SHOULD for a sender choosing what to announce — a peer that announces (and then frames its own chunks at) a smaller value is still wire-legal, and this side must parse at whatever size the peer actually announced or every later chunk boundary is misparsed. So this only enforces the hard MUST >= 1 floor (a chunk size of 0 would never make progress splitting payload) and caps at MAX_CHUNK_SIZE (a defensive ceiling, not a spec limit — see its own doc). The wire’s reserved top bit and the == 0 case are already rejected earlier, at crate::message::ProtocolControl::from_payload’s parse of the Set Chunk Size message itself, before a value ever reaches here; the floor below is this method’s own defensive backstop for any other caller.

Source

pub fn abort(&mut self, csid: u32)

Discard any partially-received message on csid (§5.4.2 Abort Message). A no-op if csid has no in-progress message.

#1108/RTMP-W2: without this, Abort was accepted and silently ignored, so in_progress stayed true and the next Type 3 chunk that actually starts a new message on that csid was instead appended to the aborted payload as a continuation — message_length bytes later, a corrupted merged message came out.

Source

pub fn push(&mut self, input: &[u8]) -> Result<Vec<Message>, RtmpError>

Feed inbound bytes; returns each complete Message decoded from the buffer (in arrival order), leaving any trailing partial chunk or partial message buffered internally for the next call.

Callers that need to react to a message’s side effects (e.g. a Set Chunk Size protocol control message, §5.4.1) before parsing the bytes that follow it in the same input — because the sender may switch to the new chunk size for its very next chunk — should use the crate-internal incremental feed/next_message pair instead, dispatching each message immediately. push collects every message from input under a single, unchanging chunk_size, which misparses a buffer that itself contains a Set Chunk Size followed by chunks already framed at the new size (see ServerSession, which uses the incremental form for exactly this reason).

§Errors

RtmpError::Malformed on structurally invalid input (e.g. a Type 1/2/3 chunk on a csid that has never seen a Type 0). Never errors merely because the input ends mid-chunk — that is buffered, not an error.

Trait Implementations§

Source§

impl Debug for ChunkAssembler

Source§

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

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

impl Default for ChunkAssembler

Source§

fn default() -> Self

Returns the “default value” for a type. Read more

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> 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, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = !

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

fn try_from(value: U) -> Result<T, !>

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.