pub struct SseParser { /* private fields */ }Expand description
Stateful SSE byte-stream parser.
Feed bytes with SseParser::feed and poll complete frames with
SseParser::next_frame.
The parser buffers bytes internally until a complete line is available, then processes each line according to the SSE spec.
§Memory limits
The parser enforces a configurable maximum event size (default 4 MiB) to
prevent unbounded memory growth from malicious or malformed streams. When
the limit is exceeded, the current event is discarded and an error is
queued. Use SseParser::with_max_event_size to configure the limit.
Implementations§
Source§impl SseParser
impl SseParser
Sourcepub fn new() -> SseParser
pub fn new() -> SseParser
Creates a new, empty SseParser with default limits (4 MiB max event size).
Sourcepub fn with_max_event_size(max_event_size: usize) -> SseParser
pub fn with_max_event_size(max_event_size: usize) -> SseParser
Creates a new SseParser with a custom maximum event size.
Events exceeding this limit will be discarded and an error queued.
Sourcepub const fn pending_count(&self) -> usize
pub const fn pending_count(&self) -> usize
Returns the number of complete frames waiting to be consumed.
Sourcepub fn feed(&mut self, bytes: &[u8])
pub fn feed(&mut self, bytes: &[u8])
Feeds raw bytes from the SSE stream into the parser.
After calling feed, call SseParser::next_frame repeatedly until
it returns None to consume all complete frames.
Sourcepub fn next_frame(&mut self) -> Option<Result<SseFrame, SseParseError>>
pub fn next_frame(&mut self) -> Option<Result<SseFrame, SseParseError>>
Returns the next complete SseFrame, or None if none are ready.
Returns Err if an event exceeded the maximum size limit.