pub struct SseDecoder { /* private fields */ }Expand description
Incremental Server-Sent Events decoder.
Accumulates event: and data: field lines and emits an SseEvent when a
blank line terminates the record (standard SSE dispatch). Multiple data:
lines within one record are joined with \n. Comment lines (those starting
with :) and unknown fields are ignored. Field values have a single leading
space after the colon stripped, per the SSE specification.
push does the newline framing internally via LineDecoder; callers that
already have whole lines can use
push_line_checked.
new uses DEFAULT_MAX_LINE_BYTES for both a single
line and the accumulated data: payload in one record.
unbounded is the explicit opt-out for trusted
in-memory inputs.
Implementations§
Source§impl SseDecoder
impl SseDecoder
Sourcepub fn new() -> Self
pub fn new() -> Self
Create an empty decoder using DEFAULT_MAX_LINE_BYTES.
Sourcepub fn unbounded() -> Self
pub fn unbounded() -> Self
Create an empty decoder with no line or event-data limit.
Use this only for trusted, already-bounded inputs.
Sourcepub fn with_max_line_bytes(max_line_bytes: usize) -> Self
pub fn with_max_line_bytes(max_line_bytes: usize) -> Self
Create an empty decoder that rejects any line, buffered partial line, or
accumulated record data longer than max_line_bytes.
Sourcepub fn push(&mut self, bytes: &[u8]) -> Result<Vec<SseEvent>, NetError>
pub fn push(&mut self, bytes: &[u8]) -> Result<Vec<SseEvent>, NetError>
Feed raw bytes; return any records completed by blank lines.
Sourcepub fn push_checked(&mut self, bytes: &[u8]) -> Result<Vec<SseEvent>, NetError>
pub fn push_checked(&mut self, bytes: &[u8]) -> Result<Vec<SseEvent>, NetError>
Feed raw bytes; return any records completed by blank lines.
Sourcepub fn push_line(&mut self, line: &str) -> Option<SseEvent>
pub fn push_line(&mut self, line: &str) -> Option<SseEvent>
Feed a single already-framed line (without its terminating newline).
Returns an SseEvent when this line is the blank line that dispatches
the accumulated record.
Sourcepub fn push_line_checked(
&mut self,
line: &str,
) -> Result<Option<SseEvent>, NetError>
pub fn push_line_checked( &mut self, line: &str, ) -> Result<Option<SseEvent>, NetError>
Feed a single already-framed line, checking line and accumulated data bounds.