Skip to main content

ChunkWriter

Struct ChunkWriter 

Source
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>

Source

pub fn new(writer: W) -> Self

Wrap an AsyncWrite transport in a chunk writer.

Source

pub fn into_inner(self) -> W

Consume the writer and return the underlying transport.

Source

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.

Source

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.

Source

pub async fn write_ctrl_in_json(&mut self, json: &[u8]) -> Result<(), RawError>

Write a client→server control chunk (stream_type 3) carrying a JSON payload (Resize, Signal, or Eof).

Source

pub async fn write_ctrl_out_json(&mut self, json: &[u8]) -> Result<(), RawError>

Write a server→client control chunk (stream_type 4) carrying a JSON payload (Exit).

Auto Trait Implementations§

§

impl<W> Freeze for ChunkWriter<W>
where W: Freeze,

§

impl<W> RefUnwindSafe for ChunkWriter<W>
where W: RefUnwindSafe,

§

impl<W> Send for ChunkWriter<W>
where W: Send,

§

impl<W> Sync for ChunkWriter<W>
where W: Sync,

§

impl<W> Unpin for ChunkWriter<W>

§

impl<W> UnsafeUnpin for ChunkWriter<W>
where W: UnsafeUnpin,

§

impl<W> UnwindSafe for ChunkWriter<W>
where W: UnwindSafe,

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<ST, DT> CastableFrom<ST, Initialized, Initialized> for DT
where ST: ?Sized, DT: ?Sized,

Source§

impl<ST, DT> CastableFrom<ST, Uninit, Uninit> for DT
where ST: ?Sized, DT: ?Sized,

Source§

impl<T> ErasedDestructor for T
where T: 'static,

Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T> Instrument for T

Source§

fn instrument(self, span: Span) -> Instrumented<Self>

Instruments this type with the provided Span, returning an Instrumented wrapper. Read more
Source§

fn in_current_span(self) -> Instrumented<Self>

Instruments this type with the current Span, returning an Instrumented wrapper. Read more
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> MaybeSendSync for T

Source§

impl<T> Read<Exclusive, BecauseExclusive> for T
where T: ?Sized,

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.
Source§

impl<T> WithSubscriber for T

Source§

fn with_subscriber<S>(self, subscriber: S) -> WithDispatch<Self>
where S: Into<Dispatch>,

Attaches the provided Subscriber to this type, returning a WithDispatch wrapper. Read more
Source§

fn with_current_subscriber(self) -> WithDispatch<Self>

Attaches the current default Subscriber to this type, returning a WithDispatch wrapper. Read more