pub struct SseDecoder { /* private fields */ }Expand description
Push-based decoder: feed bytes, receive completed events.
Implementations§
Source§impl SseDecoder
impl SseDecoder
Sourcepub fn new(max_line_bytes: usize) -> Self
pub fn new(max_line_bytes: usize) -> Self
Decoder bounding each line; events are unbounded (use Self::with_limits).
Sourcepub fn with_limits(max_line_bytes: usize, max_event_bytes: usize) -> Self
pub fn with_limits(max_line_bytes: usize, max_event_bytes: usize) -> Self
Decoder bounding each line and the accumulated bytes of one event (event name plus all data lines, one separator byte per line).
Sourcepub fn eager() -> Self
pub fn eager() -> Self
Eager decoder with the default line bound. Every data: line becomes an event as soon
as its newline arrives, carrying that line as its data, instead of waiting for the
blank line that ends the frame. A provider whose daemon ends each frame with a newline
rather than a blank line needs this; the WHATWG framing is the default.
Sourcepub fn with_eager(self) -> Self
pub fn with_eager(self) -> Self
Switch this decoder to eager mode (see SseDecoder::eager).
Sourcepub fn has_pending(&self) -> bool
pub fn has_pending(&self) -> bool
True when bytes or a frame are buffered that no event has delivered yet: a partial line,
or data lines waiting for their blank line. A stream that ends while this is true was
cut off mid-event.
Sourcepub fn finish(&mut self) -> Result<Option<SseEvent>, HttpError>
pub fn finish(&mut self) -> Result<Option<SseEvent>, HttpError>
Flush at end of stream. A final line without its newline is processed, and a complete frame still waiting for its blank line is delivered, so a daemon that closes right after its last event does not lose it. Returns at most one event. Errors (invalid UTF-8 in the final line, for example) are reported, never dropped.