pub struct StreamingDecoder { /* private fields */ }Expand description
Frame-by-frame streaming decoder.
Accumulates bytes from progressive feeding and emits decoded data objects as complete messages arrive.
Error visibility: If a scanned message fails to decode (corrupt
payload), the error is captured in last_error() and the decoder
advances past the bad message. Call last_error() after each
feed() to check for skipped messages.
Memory limit: The internal buffer is capped at 256 MiB by
default. Call set_max_buffer(n) to change it. Exceeding the
limit makes feed() return a thrown JsValue (a js_sys::Error).
Implementations§
Source§impl StreamingDecoder
impl StreamingDecoder
Sourcepub fn feed(&mut self, chunk: &[u8]) -> Result<(), JsValue>
pub fn feed(&mut self, chunk: &[u8]) -> Result<(), JsValue>
Feed a chunk of bytes into the decoder.
Internally scans for complete messages and decodes each one,
emitting individual data objects as DecodedFrames.
Returns an error if the internal buffer exceeds max_buffer bytes.
Check last_error() after feeding to detect skipped corrupt messages.
Sourcepub fn next_frame(&mut self) -> Option<DecodedFrame>
pub fn next_frame(&mut self) -> Option<DecodedFrame>
Pull the next decoded data object frame, or undefined if none ready.
In JavaScript, wasm-bindgen maps Rust None to undefined.
Use a truthiness check: while ((frame = decoder.next_frame())).
Sourcepub fn has_metadata(&self) -> bool
pub fn has_metadata(&self) -> bool
Whether global metadata has been received from at least one message.
Sourcepub fn metadata(&self) -> Result<JsValue, JsValue>
pub fn metadata(&self) -> Result<JsValue, JsValue>
Get the global metadata from the most recently decoded message.
Sourcepub fn pending_count(&self) -> usize
pub fn pending_count(&self) -> usize
Number of decoded frames ready to consume.
Sourcepub fn buffered_bytes(&self) -> usize
pub fn buffered_bytes(&self) -> usize
Total bytes buffered but not yet decoded.
Sourcepub fn last_error(&self) -> Option<String>
pub fn last_error(&self) -> Option<String>
Error message from the last skipped (corrupt) message, or null.
Cleared on each feed() call. If non-null, at least one message
found by the scanner failed to decode and was skipped.
Sourcepub fn skipped_count(&self) -> usize
pub fn skipped_count(&self) -> usize
Total number of messages that were skipped due to decode errors since the decoder was created or last reset.
Sourcepub fn set_max_buffer(&mut self, max_bytes: usize)
pub fn set_max_buffer(&mut self, max_bytes: usize)
Set the maximum internal buffer size in bytes (default: 256 MiB).
The limit applies to the total unprocessed bytes (already-buffered
bytes plus the next incoming chunk). If adding a new chunk would
exceed this limit, feed() returns an error and the chunk is not
buffered. Reducing the limit below the current buffer size takes
effect on the next feed() call.
Trait Implementations§
Source§impl Default for StreamingDecoder
impl Default for StreamingDecoder
Source§impl From<StreamingDecoder> for JsValue
impl From<StreamingDecoder> for JsValue
Source§fn from(value: StreamingDecoder) -> Self
fn from(value: StreamingDecoder) -> Self
Source§impl FromWasmAbi for StreamingDecoder
impl FromWasmAbi for StreamingDecoder
Source§impl IntoWasmAbi for StreamingDecoder
impl IntoWasmAbi for StreamingDecoder
Source§impl OptionFromWasmAbi for StreamingDecoder
impl OptionFromWasmAbi for StreamingDecoder
Source§impl OptionIntoWasmAbi for StreamingDecoder
impl OptionIntoWasmAbi for StreamingDecoder
Source§impl RefFromWasmAbi for StreamingDecoder
impl RefFromWasmAbi for StreamingDecoder
Source§type Anchor = RcRef<StreamingDecoder>
type Anchor = RcRef<StreamingDecoder>
Self for the duration of the
invocation of the function that has an &Self parameter. This is
required to ensure that the lifetimes don’t persist beyond one function
call, and so that they remain anonymous.Source§impl RefMutFromWasmAbi for StreamingDecoder
impl RefMutFromWasmAbi for StreamingDecoder
Source§impl TryFromJsValue for StreamingDecoder
impl TryFromJsValue for StreamingDecoder
Source§impl VectorFromWasmAbi for StreamingDecoder
impl VectorFromWasmAbi for StreamingDecoder
type Abi = <Box<[JsValue]> as FromWasmAbi>::Abi
unsafe fn vector_from_abi(js: Self::Abi) -> Box<[StreamingDecoder]>
Source§impl VectorIntoWasmAbi for StreamingDecoder
impl VectorIntoWasmAbi for StreamingDecoder
type Abi = <Box<[JsValue]> as IntoWasmAbi>::Abi
fn vector_into_abi(vector: Box<[StreamingDecoder]>) -> Self::Abi
Source§impl WasmDescribeVector for StreamingDecoder
impl WasmDescribeVector for StreamingDecoder
impl SupportsConstructor for StreamingDecoder
impl SupportsInstanceProperty for StreamingDecoder
impl SupportsStaticProperty for StreamingDecoder
Auto Trait Implementations§
impl Freeze for StreamingDecoder
impl RefUnwindSafe for StreamingDecoder
impl Send for StreamingDecoder
impl Sync for StreamingDecoder
impl Unpin for StreamingDecoder
impl UnsafeUnpin for StreamingDecoder
impl UnwindSafe for StreamingDecoder
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
Source§impl<T> Instrument for T
impl<T> Instrument for T
Source§fn instrument(self, span: Span) -> Instrumented<Self>
fn instrument(self, span: Span) -> Instrumented<Self>
Source§fn in_current_span(self) -> Instrumented<Self>
fn in_current_span(self) -> Instrumented<Self>
Source§impl<T> ReturnWasmAbi for Twhere
T: IntoWasmAbi,
impl<T> ReturnWasmAbi for Twhere
T: IntoWasmAbi,
Source§type Abi = <T as IntoWasmAbi>::Abi
type Abi = <T as IntoWasmAbi>::Abi
IntoWasmAbi::AbiSource§fn return_abi(self) -> <T as ReturnWasmAbi>::Abi
fn return_abi(self) -> <T as ReturnWasmAbi>::Abi
IntoWasmAbi::into_abi, except that it may throw and never
return in the case of Err.