Skip to main content

StreamingDecoder

Struct StreamingDecoder 

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

Incremental decoder for a Content-Encoding value: one coding, or a list of them applied in order (see StreamingDecoder::from_codings).

Implementations§

Source§

impl StreamingDecoder

Source

pub fn new(encoding: &str, limit: usize) -> Result<Self>

A decoder for one Content-Encoding header value, which may be a list ("gzip, br"). The same as from_codings with that one value.

Source

pub fn from_codings<I>(values: I, limit: usize) -> Result<Self>
where I: IntoIterator, I::Item: AsRef<[u8]>,

A decoder for a Content-Encoding field: pass every header line’s value, in order. Repeated lines are merged as for any list-valued field (RFC 9110 section 5.3), and each value may itself be a comma-separated list.

Codings are listed in the order they were applied, so they are decoded in reverse: in gzip, br the last-listed br is outermost and decoded first. Names are case-insensitive, x-gzip is gzip, and identity and empty list elements are skipped; no coding at all decodes as identity. An unknown coding, or more than MAX_CODINGS, fails with UND_ERR_NOT_SUPPORTED.

One coding decodes straight into the caller’s output as before. Each further coding stages its output in a fixed 16 KiB buffer allocated here and kept across reset; limit bounds every coding’s output, not only the last, so an outer coding cannot expand without bound into an inner one that produces nothing.

Source

pub fn reset(&mut self, limit: usize) -> Result<()>

Reuse algorithm and scratch storage for another body of the same encoding. Warm up with the largest expected body shape before measuring allocations.

Source

pub fn process( &mut self, input: &[u8], output: &mut [u8], end: bool, ) -> Result<DecodeStep>

Decode as far as input and output allow: the call returns only when the body is finished, the decoder needs more input, or output is full, and DecodeStep says which. One call per transport read and one per full output buffer is enough; there is no need to loop until a step makes no progress.

end means no more encoded bytes will arrive, not that output is unbounded.

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.