pub struct ChunkWriter { /* private fields */ }Expand description
Stateless-per-message outbound chunk writer (§5.3): serializes a
Message into chunk bytes at the current chunk size.
Simple, always-correct strategy: the first chunk is always Type 0 (full absolute-timestamp header) and every continuation chunk is Type 3 (0-byte header, inheriting everything). This is spec-valid — Type 1/2’s more compact delta-based headers are a size optimisation this writer does not perform.
Implementations§
Source§impl ChunkWriter
impl ChunkWriter
Sourcepub fn set_chunk_size(&mut self, chunk_size: ChunkSize)
pub fn set_chunk_size(&mut self, chunk_size: ChunkSize)
Update the chunk size used for subsequent ChunkWriter::write
calls (called on sending a Set Chunk Size protocol control message,
§5.4.1). The value is adopted verbatim — a validated ChunkSize
is never clamped — so the framing always matches the size the
matching Set Chunk Size message announced.
Sourcepub fn write(&mut self, msg: &Message) -> Result<Vec<u8>, RtmpError>
pub fn write(&mut self, msg: &Message) -> Result<Vec<u8>, RtmpError>
Serialize msg into chunk bytes at the current chunk size: a Type 0
first chunk carrying up to chunk_size payload bytes, then Type 3
continuation chunks for the remainder.
§Errors
Returns RtmpError::FieldOverflow if msg.payload is 16 MiB
(2^24) or larger — message_length is a UI24 field (§5.3.1.2) and
cannot represent it (#1129: unfixed, payload.len() as u32 then the
UI24 writer silently kept only the low 24 bits, misframing every
later message on the chunk stream).
Returns RtmpError::InvalidChunkStreamId if msg.chunk_stream_id
is outside the basic header’s encodable range (2..=65599). Every
chunk_stream_id produced by ChunkAssembler::push satisfies this
(BasicHeader::parse never yields one outside the range); callers
building a Message from scratch must respect it.