Skip to main content

Decoder

Struct Decoder 

Source
pub struct Decoder { /* private fields */ }

Implementations§

Source§

impl Decoder

Source

pub fn new(mode: Mode, limits: Limits) -> Self

Source

pub fn response_to(&mut self, method: &str)

Must precede response parsing. Pipelining is intentionally not provided.

Source

pub fn reusable(&self) -> bool

Source

pub fn wants_step(&self) -> bool

True when the decoder holds an event that reads no input, so the host must call receive again even with nothing new to feed it - an empty slice will do. That event is Event::End or Event::Upgrade. It becomes pending when the last body byte, the final chunk or the head of a bodiless message is consumed, and after eof ends a close-delimited body.

This is the signal a host that drives on “bytes to feed” is missing. Such a host stops once its buffer is empty and never sees End: the message sits finished inside the decoder, the connection is not reusable, and only the peer’s idle timeout ends the exchange. Loop while !input.is_empty() || decoder.wants_step(), or use the Step contract’s condition, which covers the same case.

Source

pub fn is_mid_message(&self) -> bool

True between a message’s Event::Head and the point its end is reached: the body, chunk framing or trailers are still being read. False before the head (including after an Event::Informational, which is not the message), once End or Upgrade is owed or delivered, and after a failure. Bytes of a head the host has buffered but not yet completed are the host’s to know; the decoder has not accepted them.

A close-delimited body is mid-message too, though EOF is its legal end: ask eof_is_clean to tell the two apart.

Source

pub fn eof_is_clean(&self) -> bool

Whether the transport ending now would be a clean end rather than a truncation: exactly the cases in which eof returns Ok, answered without changing any state. True inside a close-delimited body and once the message is complete; false inside a framed body, before a head arrives and after a failure. So a host whose read returned zero can choose what to do - retry, fail with its own diagnosis, log - before it commits to eof.

Before a head is always “not clean” here, because a client that sees EOF there got no response. A server whose connection closes while idle between requests (with no buffered head bytes) treats that as an ordinary close on its own.

Source

pub fn reset(&mut self) -> Result<()>

Source

pub fn receive<'a>(&mut self, input: &'a [u8]) -> Result<Step<'a>>

Source

pub fn eof(&mut self) -> Result<()>

Declare the end of input. Ends a close-delimited body (leaving Event::End owed, see wants_step); anywhere eof_is_clean is false it fails the decoder.

Trait Implementations§

Source§

impl Debug for Decoder

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more

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.