Skip to main content

StreamParser

Struct StreamParser 

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

Frames messages out of a byte stream.

Holds at most one partial message. Completed messages are split off the buffer with BytesMut::split_to, so each message owns a view of the same allocation rather than a copy.

Implementations§

Source§

impl StreamParser

Source

pub fn new(limits: Limits) -> Self

A parser with the given limits.

Source

pub fn take_keepalives(&mut self) -> usize

How many CRLF pairs have been discarded between messages, resetting the count.

RFC 5626 §4.4.1’s keep-alive is framed entirely out of bytes RFC 3261 §7.5 tells a parser to ignore: CRLFCRLF is the ping, a lone CRLF is the pong. So the parser goes on ignoring them and counts them on the way past, and a transport that is waiting for a pong asks.

The count is of pairs, not of pings: a ping is two and a pong is one, and which it was depends on who sent it — which the parser has no way to know and no business deciding.

Source

pub fn pending(&self) -> usize

Bytes buffered but not yet part of a completed message.

Exposed so a transport can time out a peer that sends a header section and then stops — a slow-loris defence the parser cannot mount for itself.

Source

pub fn push(&mut self, chunk: &[u8]) -> Result<Vec<Message>, ParseError>

Append bytes, returning every message they completed, in order.

An error is fatal for the connection: framing is lost and sipx does not attempt to resynchronize, because guessing where the next message starts is how a body becomes a request (RFC 4475 §3.1.2.3). Subsequent calls keep returning the same error.

Trait Implementations§

Source§

impl Debug for StreamParser

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> Same for T

Source§

type Output = T

Should always be Self
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.