How a reading is chosen
The inspector has no weights and no confidence number. It tries candidates, counts named evidence, and compares candidates in a fixed order; the first difference decides. This page is that order.
- All zeros (not empty)? Padding; empty: Unknown
- Header candidates. For each schema, read its own header layout. Both ids found:
Exact; only the template id:TemplateOnly. Walk each one; a broken hard rule (H1 to H5) ends it, marked truncated. Each walk is one unit of the work budget. - An
Exact, complete candidate? Yes: go to 6. - Printable UTF-8? Text
- No header candidate complete? Read the bytes as every message's bare body; keep those that use every byte with no evidence against:
Inferred. - Rank: match class, complete, bytes consumed, evidence against, version distance. One best: Message; a tie: Ambiguous; none: Unknown. If the work budget ran out while the candidates were read, the payload is
Unknown, marked with the work limit, never a ranking of a subset. - Retry. Bytes left after a complete message are read again as records one after another (after a truncated one they are kept as unknown bytes); var data with no
characterEncodingis read again one level deeper, up to the depth limit.
Candidates
A candidate is “these bytes are message M of schema S, starting at the first
byte”. Each loaded schema reads the header with its own header composite
(headerType, any offsets and widths, the schema’s byte order). When the
header’s templateId is a message of that schema, the candidate is walked:
header, root block, groups (nested), var data, in wire order.
Versioning follows the generated decoders. The acting block length is the
wire blockLength; a field whose sinceVersion is above the wire version,
or that lies past the acting block length, is absent; bytes of a root
block or group entry that no field shows are skipped, with a note: bytes past
the schema’s block (a newer writer’s fields, or bytes no version explains),
and an older writer’s bytes under fields newer than its version.
Hard rules
Breaking one ends the walk at that offset. What was read so far is kept, the
message is marked truncated with the rule, the group or var data it stopped at
prints as cut (or as the entries read, of the count on the wire), and the
bytes after the cut follow as unknown bytes.
| Rule | Check |
|---|---|
| H1 | The header fits in the bytes |
| H2 | The wire blockLength fits in the remaining bytes |
| H3 | When the wire version is at or above the schema’s, the wire blockLength is at least the schema’s block length |
| H4 | Each group dimension fits, numInGroup times its blockLength fits, and each entry’s block fits where the entry starts |
| H5 | Each var-data length prefix fits, and so do its bytes |
| H6 | A group whose entries take no bytes is walked once, never numInGroup times: one entry stands for all of them |
Evidence
Evidence is counted and shown, never fatal. pretty prints evidence for with
+ and against with -, with the field it concerns.
| Against | For |
|---|---|
| An enum value that is neither a valid value nor null | Every enum holds a valid value or null |
| A set bit the schema does not define | Every char field is printable, or zero-padded |
A value outside a declared minValue/maxValue (a var-data length too) | Every var data with a characterEncoding is valid in it |
A char field with unprintable bytes | The header’s schemaId and templateId were both found |
Var data invalid in its declared characterEncoding | The wire version equals the schema version |
At the schema’s version, a wire blockLength that differs from the schema’s | The message ends exactly at the end of the bytes |
| Bytes left after the message | A note, not a vote: block bytes no field shows (past the schema’s fields, or under fields newer than the wire version), skipped |
Text in a known encoding (UTF-8, ASCII, ISO-8859-1) is decoded; text
invalid in its encoding is shown as bytes, never repaired. Text in an
encoding the inspector does not decode is shown as bytes too, and never read
again as SBE.
The comparison order
| Order | Evidence | Better is |
|---|---|---|
| 1 | Match class | Exact, then TemplateOnly, then Inferred |
| 2 | The walk broke no hard rule | complete |
| 3 | Bytes consumed | more |
| 4 | Evidence against | fewer |
| 5 | Version distance | equal, then an older writer, then a newer one |
- Candidates equal on all five are
Ambiguous, every one listed with its evidence (at mostLimits::max_candidates, then a count of the rest). Textloses to anExact, complete message and beats every other candidate. All-zero bytes arePadding.Inferredbodies are tried only when no header-based candidate completes, and one is kept only when it uses every byte and has no evidence against. A message of plain integers fits any bytes of its length, so every survivor is listed.- Nothing left:
Unknown, the bytes in full.
Limits and untrusted input
Schemas and payloads are both untrusted. For any bytes and any schema that
parses, inspect does not panic, does not loop without bound and returns a
reading.
Limits field | Default | Past it |
|---|---|---|
max_depth | 8 | var data deeper than this is Unknown, marked with the depth limit |
max_input | 16 MiB | the whole input is Unknown, marked with the input-size limit |
max_candidates | 8 | an Ambiguous lists this many and counts the rest |
max_walks | 20 000 | nothing more is walked; what is left is Unknown, marked with the work limit |
max_skip | 64 | the longest leading header skip-then tries (framing) |
The work budget is one unit per candidate walk, plus one per 64 group entries
walked (ENTRIES_PER_UNIT) and one per 64 KiB of a long text check, across
framings, retries and scans, so one walk over a long buffer is paid for too.
When the budget runs out while a payload’s candidates are being read, the
whole payload is Unknown, marked with the work limit: a ranking over only
the candidates read so far could be a confident wrong answer.
Inspector::work() reports the count and every limit hit. At load, groups
and composites nested deeper than 32 levels are refused. A schema with a
DTD (and so any entity-expansion bomb) is refused by the XML parser before
ergo-sbe reads it. A fuzz target, inspect_bytes in sbe/fuzz, drives
schemas and bytes together.