Decoder

Struct Decoder 

Source
pub struct Decoder<'a> { /* private fields */ }
Expand description

Decodes headers encoded using HPACK.

For now, incremental decoding is not supported, i.e. it is necessary to pass in the entire encoded representation of all headers to the decoder, rather than processing it piece-by-piece.

Implementations§

Source§

impl<'a> Decoder<'a>

Represents a decoder of HPACK encoded headers. Maintains the state necessary to correctly decode subsequent HPACK blocks.

Source

pub fn new() -> Decoder<'a>

Creates a new Decoder with all settings set to default values.

Source

pub fn set_max_table_size(&mut self, new_max_size: usize)

Sets a new maximum dynamic table size for the decoder.

If max_allowed_table_size is set, new_max_size must be <= to it.

Source

pub fn set_max_allowed_table_size(&mut self, max_allowed_size: usize)

Sets max allowed table size: any “dynamic table size updates” that try to bring the table size over that value will error out with DecoderError::InvalidMaxDynamicSize

Source

pub fn decode_with_cb( &mut self, buf: &[u8], cb: impl FnMut(Cow<'_, [u8]>, Cow<'_, [u8]>), ) -> Result<(), DecoderError>

Decodes the headers found in the given buffer buf. Invokes the callback cb for each decoded header in turn, by providing it the header name and value as Cow byte array slices.

The callback is free to decide how to handle the emitted header, however the Cow cannot outlive the closure body without assuming ownership or otherwise copying the contents.

This is due to the fact that the header might be found (fully or partially) in the header table of the decoder, in which case the callback will have received a borrow of its contents. However, when one of the following headers is decoded, it is possible that the header table might have to be modified; so the borrow is only valid until the next header decoding begins, meaning until the end of the callback’s body.

If an error is encountered during the decoding of any header, decoding halts and the appropriate error is returned as the Err variant of the Result.

Source

pub fn decode(&mut self, buf: &[u8]) -> DecoderResult

Decode the header block found in the given buffer.

The decoded representation is returned as a sequence of headers, where both the name and value of each header is represented by an owned byte sequence (i.e. Vec<u8>).

The buffer should represent the entire block that should be decoded. For example, in HTTP/2, all continuation frames need to be concatenated to a single buffer before passing them to the decoder.

Trait Implementations§

Source§

impl Default for Decoder<'_>

Source§

fn default() -> Decoder<'static>

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

Auto Trait Implementations§

§

impl<'a> Freeze for Decoder<'a>

§

impl<'a> RefUnwindSafe for Decoder<'a>

§

impl<'a> Send for Decoder<'a>

§

impl<'a> Sync for Decoder<'a>

§

impl<'a> Unpin for Decoder<'a>

§

impl<'a> UnwindSafe for Decoder<'a>

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

Source§

type Error = Infallible

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

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

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