pub struct SseDecoder { /* private fields */ }Expand description
An incremental text/event-stream decoder.
Push bytes, pull frames. It owns a buffer for the partial line at the end of each chunk, which is why it has to be a struct and not a function.
Implementations§
Source§impl SseDecoder
impl SseDecoder
Sourcepub fn with_max_frame_size(self, bytes: usize) -> Self
pub fn with_max_frame_size(self, bytes: usize) -> Self
Sets the cap on a single frame.
Sourcepub fn max_frame_size(&self) -> usize
pub fn max_frame_size(&self) -> usize
The cap on a single frame, in bytes.
Sourcepub fn push(&mut self, bytes: &[u8]) -> Result<()>
pub fn push(&mut self, bytes: &[u8]) -> Result<()>
Feeds the decoder a chunk of the response body.
§Errors
Error::Decode when the frame being assembled exceeds
SseDecoder::max_frame_size — a server that never sends a line break
would otherwise grow this buffer without bound.
Sourcepub fn next_frame(&mut self) -> Result<Option<SseFrame>>
pub fn next_frame(&mut self) -> Result<Option<SseFrame>>
Pulls the next complete frame, if the bytes pushed so far contain one.
§Errors
Error::Decode when the bytes are not UTF-8.
Sourcepub fn finish(&mut self) -> Result<Vec<SseFrame>>
pub fn finish(&mut self) -> Result<Vec<SseFrame>>
Drains the decoder at the end of the stream.
A body that stops without the blank line that terminates its last frame is common enough — a closed connection, a server that forgets — that dropping the frame would lose real events. Anything still buffered is dispatched here.
§Errors
Error::Decode when the trailing bytes are not UTF-8.
Trait Implementations§
Source§impl Clone for SseDecoder
impl Clone for SseDecoder
Source§fn clone(&self) -> SseDecoder
fn clone(&self) -> SseDecoder
1.0.0 (const: unstable) · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
source. Read more