Skip to main content

FrameDecoder

Struct FrameDecoder 

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

An incremental frame decoder, fed chunks as they arrive.

Written the same way as crate::capsule::CapsuleDecoder, and for the same reason: frames do not align with stream chunks in either direction, so the decoder has to be a state machine that can be fed a byte at a time – which is exactly how the tests below feed it.

Public, though nothing outside this module constructs one at run time: FrameReader is what the server uses, and crate::h3api deliberately re-exports neither. What needs this is tests/it_fuzz.rs, where the properties about chunk boundaries and about which frame type belongs on which stream are worth far more when they can be stated against the state machine itself – a byte at a time, at chosen split points, on a StreamKind the test picks – than against a loopback QUIC connection whose packetisation is quinn’s to decide. It is documented rather than hidden because this module’s own prose already names it as the design’s centre.

Implementations§

Source§

impl FrameDecoder

Source

pub fn new(stream: StreamKind, budget: Arc<BufferBudget>) -> Self

A decoder positioned at the start of a stream’s frame sequence, drawing on budget for whatever it has to buffer.

Source

pub fn push(&mut self, chunk: Bytes)

Hands the decoder the next chunk of stream.

Only legal once Self::next_item has asked for more, which is the only state in which the previous chunk is spent.

Source

pub fn connect_completed(&mut self)

Narrows the frame rules to the ones RFC 9114 §4.4 gives a tunnel.

Called once the 2xx answering a CONNECT has gone out, which is what “completed” means in that section. From here a HEADERS frame is a connection error like every other known type but DATA, and it is refused from its header rather than after its payload – so a peer cannot hold the connection’s buffering budget with field sections it was never allowed to send.

Source

pub fn at_frame_boundary(&self) -> bool

Whether the stream could end here without truncating a frame.

RFC 9114 §7.1: “When a stream terminates cleanly, if the last frame on the stream was truncated, this MUST be treated as a connection error of type H3_FRAME_ERROR.”

Source

pub fn next_item(&mut self) -> Result<Option<Item>, Error>

The next item, or None when more bytes are needed.

Trait Implementations§

Source§

impl Debug for FrameDecoder

Source§

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

Formats the value using the given formatter. Read more
Source§

impl Drop for FrameDecoder

Source§

fn drop(&mut self)

Returns the budget a half-received frame was holding (D77).

The guard that makes the accounting sound: a stream can end at any point, and most of the ways it ends are the peer’s to choose – a RESET_STREAM, a STOP_SENDING answered, the request deadline of D76 expiring, the connection going away. None of them reaches the decoding loop, and a share not returned on any one of them would be a slow leak of the connection’s own allowance, ending in a peer being refused a request it was entitled to.

Source§

fn pin_drop(self: Pin<&mut Self>)

🔬This is a nightly-only experimental API. (pin_ergonomics)
Execute the destructor for this type, but different to Drop::drop, it requires self to be pinned. 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.

§

impl<T> Instrument for T

§

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

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

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

impl<T> WithSubscriber for T

§

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
§

fn with_current_subscriber(self) -> WithDispatch<Self>

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