The depth and items limits checked on encoded JSON, before it is decoded
(spec/01 §5, gate 2).
A decoder that builds the whole value first has already paid for it when a limit is found: a document nested a million deep, or holding a million entries, is in memory before anything refuses it. The scan walks the bytes instead, tracking strings and their escapes, the nesting and the entries of each object and array, and stops at the first limit it passes. It builds no value: what it holds is one frame per open object or array, never more than the depth limit, and the key of each open object, so the fault can name its path.
The scan is not a validator. It reads well-formed JSON exactly, and on malformed input it never fails: whatever it can't make sense of, it leaves to the decoder, which reports it. A key that appears twice in one object is counted twice, as the document holds it twice.
Summary
Functions
:ok, or the first depth or items limit the encoded document passes, at its path.
Functions
@spec scan(binary(), Macaw.Layers.Limits.t()) :: :ok | {:error, Macaw.Layers.Fault.t()}
:ok, or the first depth or items limit the encoded document passes, at its path.
An object or array over the items limit is reported once it holds one entry more than
the limit, as {path, {:limit, :items, max, max + 1}}; a container beyond the depth
limit as {path, {:limit, :depth, max, max + 1}}.