Set the complete profile before parsing
The Parser_Profile selects RFC 8949 syntax, Unicode scalar validation, and well-formed CBOR acceptance. Maximum_Syntax_Depth separately bounds arrays, maps, tags, and indefinite strings.
Profile : constant Profiles.Parser_Profile :=
(Syntax => (Family => Profiles.RFC_8949, Version => 1),
Unicode => (Family => Profiles.Unicode_Scalars, Version => 1),
Acceptance => (Family => Profiles.Well_Formed_CBOR, Version => 1));
-- The root map needs one syntax frame. This example gives the event array
-- an arbitrary lower bound.
Parser : Parsing.Parser (Maximum_Syntax_Depth => 1);
Events : Parsing.Event_Array (-4 .. 1);
Diagnostic : Errors.Diagnostic;
Accepted : Boolean := False;
Choose one event or a batch
Step returns at most one event and never consumes beyond it. Drain fills the caller-owned event array by repeating the same admission engine. Counts are relative to each array’s lower bound.
Need_Input means the parser consumed the complete supplied chunk. Output_Full means the caller must process the eligible provisional prefix counted by Drain_Result.Produced before supplying the unconsumed suffix.
Keep CBOR structure visible
The event grammar exposes definite and indefinite strings, array lengths, map pair counts, tags, simple values, and raw-width floats. A tag wraps exactly one nested data item. Tag numbers remain unsigned CBOR syntax; the crate assigns no schema identity.
Resolve borrowed fragments against the producing input
A byte-string fragment always identifies borrowed input. A text fragment identifies a borrowed input range or one owned Inline_Text_Scalar assembled in fixed parser storage. Call Resolve_Raw_Range for a borrowed event. If its status is Slice_Resolved, apply the returned range only to the exact unchanged input passed to the producing call. A later parser call alone does not invalidate the range. Copy borrowed payload before the caller mutates, reuses, or releases that input.
Accept only the complete document
Every event is provisional. After Document_Complete, commit the application candidate. Use Abort_Document to end an incomplete operation. Use Reset from Failure_Pending or a terminal state to validate a complete new profile and restart at byte zero.