Skip to main content

SseDecoder

Struct SseDecoder 

Source
pub struct SseDecoder { /* private fields */ }
Expand description

Push-based decoder: feed bytes, receive completed events.

Implementations§

Source§

impl SseDecoder

Source

pub fn new(max_line_bytes: usize) -> Self

Decoder bounding each line; events are unbounded (use Self::with_limits).

Source

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).

Source

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.

Source

pub fn with_eager(self) -> Self

Switch this decoder to eager mode (see SseDecoder::eager).

Source

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.

Source

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.

Source

pub fn push(&mut self, bytes: &[u8]) -> Result<Vec<SseEvent>, HttpError>

Trait Implementations§

Source§

impl Debug for SseDecoder

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
Source§

impl Default for SseDecoder

Source§

fn default() -> Self

Returns the “default value” for a type. Read more

Auto Trait Implementations§

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = !

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, !>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.