pub struct JsonSplitter { /* private fields */ }Expand description
Splits a byte stream into complete top-level JSON values.
Implementations§
Source§impl JsonSplitter
impl JsonSplitter
Sourcepub fn strict() -> Self
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.
Sourcepub fn error(&self) -> Option<&MalformedJson>
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.
Sourcepub fn feed(&mut self, chunk: &[u8], out: &mut Vec<String>)
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.
Sourcepub fn has_partial(&self) -> bool
pub fn has_partial(&self) -> bool
True when there are buffered bytes of an unfinished value.
Sourcepub fn finish(&mut self, out: &mut Vec<String>) -> Result<(), FinishError>
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).