pub struct StreamingJsonDecoder { /* private fields */ }Expand description
Streaming JSON decoder for Server-Sent Events (SSE)
This decoder handles newline-delimited JSON streams commonly used in HTTP/SSE transports.
§Security
The decoder enforces a maximum buffer size of 1MB to prevent denial-of-service attacks via unbounded memory consumption. If an attacker sends continuous data without newlines, the buffer will be cleared after exceeding the limit.
Implementations§
Source§impl StreamingJsonDecoder
impl StreamingJsonDecoder
Sourcepub fn with_capacity(capacity: usize) -> Self
pub fn with_capacity(capacity: usize) -> Self
Create with pre-allocated buffer capacity and default limit
Sourcepub fn with_max_size(max_size: usize) -> Self
pub fn with_max_size(max_size: usize) -> Self
Sourcepub fn feed(&mut self, data: &[u8])
pub fn feed(&mut self, data: &[u8])
Feed data into the decoder
§Security
If the buffer exceeds the maximum size, it will be cleared and
an error will be returned on the next try_decode call.
Sourcepub fn try_decode<T: DeserializeOwned>(&mut self) -> CodecResult<Option<T>>
pub fn try_decode<T: DeserializeOwned>(&mut self) -> CodecResult<Option<T>>
Try to decode the next complete message
Returns Some(T) if a complete message is available,
None if more data is needed.
Sourcepub fn max_buffer_size(&self) -> usize
pub fn max_buffer_size(&self) -> usize
Get maximum buffer size
Trait Implementations§
Source§impl Debug for StreamingJsonDecoder
impl Debug for StreamingJsonDecoder
Auto Trait Implementations§
impl Freeze for StreamingJsonDecoder
impl RefUnwindSafe for StreamingJsonDecoder
impl Send for StreamingJsonDecoder
impl Sync for StreamingJsonDecoder
impl Unpin for StreamingJsonDecoder
impl UnsafeUnpin for StreamingJsonDecoder
impl UnwindSafe for StreamingJsonDecoder
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more