Skip to content

JSONReassembler

[Source]

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.

class ref JSONReassembler is
  JSONTokenNotify ref

Implements


Constructors

create

[Source]

new ref create()
: JSONReassembler ref^

Returns


Public Functions

add

[Source]

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()).

fun ref add(
  token: JSONToken)
: None val

Parameters

Returns


apply

[Source]

JSONTokenNotify entry point — folds the token in, ignoring parser.

fun ref apply(
  parser: JSONTokenParser ref,
  token: JSONToken)
: None val

Parameters

Returns


take_values

[Source]

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.

fun ref take_values()
: Array[JSONValue] iso^

Returns


mid_value

[Source]

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().

fun box mid_value()
: Bool val

Returns