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
impl StreamParser
Sourcepub fn take_keepalives(&mut self) -> usize
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.
Sourcepub fn pending(&self) -> usize
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.
Sourcepub fn push(&mut self, chunk: &[u8]) -> Result<Vec<Message>, ParseError>
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.