pub struct ChunkWriter<W: AsyncWrite + Unpin> { /* private fields */ }Expand description
Writes raw chunks to an AsyncWrite transport.
ChunkWriter::write_chunk writes the 5-byte header then the payload
(if non-empty), then flushes. ChunkWriter::write_stdin,
ChunkWriter::write_ctrl_in_json, and
ChunkWriter::write_ctrl_out_json are convenience helpers for the
most common write paths.
Every write validates before touching the transport: a stream_type
above 4 or a payload longer than MAX_CHUNK_LEN returns
RawError::InvalidStreamType / RawError::ChunkTooLarge instead
of writing a header the peer cannot frame (a truncated u32 length
would corrupt the stream). An empty payload writes the same header as
a zero-length payload — every helper takes &[u8]-shaped input and
emits length == 0 with no payload bytes.
Implementations§
Source§impl<W: AsyncWrite + Unpin> ChunkWriter<W>
impl<W: AsyncWrite + Unpin> ChunkWriter<W>
Sourcepub fn new(writer: W) -> Self
pub fn new(writer: W) -> Self
Wrap an AsyncWrite transport in a chunk writer.
Sourcepub fn into_inner(self) -> W
pub fn into_inner(self) -> W
Consume the writer and return the underlying transport.
Sourcepub async fn write_chunk(&mut self, chunk: &Chunk) -> Result<(), RawError>
pub async fn write_chunk(&mut self, chunk: &Chunk) -> Result<(), RawError>
Write a chunk: header + payload (if non-empty) + flush. The
chunk’s stream_type and payload length are validated first —
an invalid chunk fails locally with RawError::InvalidStreamType
or RawError::ChunkTooLarge instead of corrupting the peer’s
framing.
Sourcepub async fn write_stdin(&mut self, bytes: &[u8]) -> Result<(), RawError>
pub async fn write_stdin(&mut self, bytes: &[u8]) -> Result<(), RawError>
Write a stdin chunk (stream_type 0) directly from a byte slice. An empty slice writes the zero-length EOF sentinel.