JSONReassembler¶
Assembles a run of JSON tokens into JSONValues.
This is the opt-in path from a token stream back to a materialized value. Plug
it into a JSONTokenParser — it is a JSONTokenNotify, so tokens flow
into it directly — or hand it tokens yourself with add(). Either way,
take_values() returns the top-level values that have completed, the same
JSONValue the batch JSONParser would build:
let re = JSONReassembler
let parser = JSONTokenParser(re)
parser.feed(chunk)?
for value in re.take_values().values() do
// value : JSONValue — use with JSONNav, JSONLens, JSONPath, JSONPrinter
end
Memory is the caller's choice: building a value costs memory proportional to that value, so hand the reassembler only the tokens you actually want materialized and drop the rest. There is no built-in size cap on what it builds, so do not blind-drain an untrusted stream into it.
take_values() returns only top-level values that have completed, and
drains them — it is not a plain accessor. If a run ends part-way through
a value, that value stays buffered — mid_value() reports it — and the
tokens that finish it can arrive later. add() expects tokens in the
order JSONTokenParser emits them; a run that is not a valid emission
sequence produces an unspecified result.
Implements¶
- JSONTokenNotify ref
Constructors¶
create¶
Returns¶
- JSONReassembler ref^
Public Functions¶
add¶
Fold one token into the value under construction. Tokens must arrive in the
order JSONTokenParser emits them; a run that is not a valid emission
sequence produces an unspecified result (but never corrupts a well-formed
run that follows a take_values()).
Parameters¶
- token: JSONToken
Returns¶
- None val
apply¶
JSONTokenNotify entry point — folds the token in, ignoring parser.
Parameters¶
- parser: JSONTokenParser ref
- token: JSONToken
Returns¶
- None val
take_values¶
Take the top-level values completed since the last call, and reset — a
second call returns an empty array unless more values have completed. A
value whose root container has not yet closed is not included; check
mid_value() for it.
Returns¶
mid_value¶
True while tokens have been folded for a value that has not closed yet.
This reports only the reassembler's own buffered partial; for byte-level
truncation of a stream, use JSONTokenParser.incomplete().
Returns¶
- Bool val