Skip to main content

JsonSplitter

Struct JsonSplitter 

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

Splits a byte stream into complete top-level JSON values.

Implementations§

Source§

impl JsonSplitter

Source

pub fn new() -> Self

Create a new splitter in the default, non-validating mode.

Source

pub fn strict() -> Self

Create a splitter in strict mode.

Strict mode rejects structural framing violations — currently a closing bracket (} or ]) seen at depth 0 with no matching open, as in }{"a":1}. The offending byte is dropped (never emitted as a bogus value) and the first such violation is recorded as a MalformedJson error, retrievable via error and returned from finish. Well-formed values continue to be emitted as usual; only the malformed framing is suppressed.

Source

pub fn error(&self) -> Option<&MalformedJson>

The first strict-mode framing violation seen so far, if any.

Always None for a splitter created with new.

Source

pub fn feed(&mut self, chunk: &[u8], out: &mut Vec<String>)

Feed a chunk of bytes. Each completed top-level value is decoded (lossy UTF-8) and pushed onto out.

Source

pub fn has_partial(&self) -> bool

True when there are buffered bytes of an unfinished value.

Source

pub fn finish(&mut self, out: &mut Vec<String>) -> Result<(), FinishError>

Signal end of stream.

A bare top-level scalar (number, true, false, null) is normally only emitted once a following separator proves it complete. If the stream ends right after such a scalar there is no separator, so this method flushes it onto out.

If the stream ends while still inside an object, array, or string literal — i.e. the value was genuinely truncated mid-flight — the buffered bytes are dropped and a TruncatedJson error is returned so the caller can distinguish a clean end from a cut connection.

In strict mode, a framing violation recorded earlier (see strict) takes priority: it is returned as a FinishError::Malformed. A clean truncation is FinishError::Truncated.

Either way the splitter is reset and may be reused for a fresh stream (the strict/non-strict mode itself is preserved).

Trait Implementations§

Source§

impl Debug for JsonSplitter

Source§

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

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

impl Default for JsonSplitter

Source§

fn default() -> JsonSplitter

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