pub struct FrameReader { /* private fields */ }Expand description
Assembles SSE blocks out of arbitrarily chunked bytes.
Fed whatever the transport delivers; yields complete frames. The buffer is retained between calls because a frame routinely spans two reads, and dropping it per read is what turns a normal stream into a stream of one-byte events.
Implementations§
Source§impl FrameReader
impl FrameReader
Sourcepub fn push(&mut self, chunk: &[u8]) -> Result<Vec<SseEvent>, FrameError>
pub fn push(&mut self, chunk: &[u8]) -> Result<Vec<SseEvent>, FrameError>
Feeds bytes and yields every complete frame they finished.
Yields in wire order and stops at the first partial block, because anything after an unterminated block is inside that block — the grammar has no way to say “and here is the next event”.
§Errors
FrameError::BlockTooLong if the buffered block grows past
MAX_BLOCK before a terminator arrives, or FrameError::Grammar if
a completed block does not parse.
Sourcepub fn into_partial(self) -> Option<Vec<u8>>
pub fn into_partial(self) -> Option<Vec<u8>>
Takes the bytes of a block that never got its terminator.
None for a stream that ended cleanly — one whose trailing block is
absent, or complete. Some is the difference between a connection that
dropped mid-event and one that ended on a boundary, and it is what
decides whether a resume has to guess.