Skip to main content

SseParser

Struct SseParser 

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

The internal frame queue is also bounded (default 4096 frames) to prevent OOM from streams that produce many oversized-event errors without the consumer draining them.

Implementations§

Source§

impl SseParser

Source

pub fn new() -> Self

Creates a new, empty SseParser with default limits (4 MiB max event size).

Source

pub fn with_max_event_size(max_event_size: usize) -> Self

Creates a new SseParser with a custom maximum event size.

Events exceeding this limit will be discarded and an error queued.

Source

pub const fn with_max_queued_frames(self, max: usize) -> Self

Sets the maximum number of frames that can be buffered before the oldest frame is dropped. Prevents unbounded memory growth if the consumer is slower than the producer.

Source

pub fn pending_count(&self) -> usize

Returns the number of complete frames waiting to be consumed.

Source

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.

Source

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.

Trait Implementations§

Source§

impl Debug for SseParser

Source§

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

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

impl Default for SseParser

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> Instrument for T

Source§

fn instrument(self, span: Span) -> Instrumented<Self>

Instruments this type with the provided Span, returning an Instrumented wrapper. Read more
Source§

fn in_current_span(self) -> Instrumented<Self>

Instruments this type with the current Span, returning an Instrumented wrapper. Read more
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> IntoRequest<T> for T

Source§

fn into_request(self) -> Request<T>

Wrap the input message T in a tonic::Request
Source§

impl<T> Same for T

Source§

type Output = T

Should always be Self
Source§

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

Source§

type Error = Infallible

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

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

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.
Source§

impl<V, T> VZip<V> for T
where V: MultiLane<T>,

Source§

fn vzip(self) -> V

Source§

impl<T> WithSubscriber for T

Source§

fn with_subscriber<S>(self, subscriber: S) -> WithDispatch<Self>
where S: Into<Dispatch>,

Attaches the provided Subscriber to this type, returning a WithDispatch wrapper. Read more
Source§

fn with_current_subscriber(self) -> WithDispatch<Self>

Attaches the current default Subscriber to this type, returning a WithDispatch wrapper. Read more