Keyboard shortcuts

Press ← or → to navigate between chapters

Press S or / to search in the book

Press ? to show this help

Press Esc to hide this help

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.

  1. All zeros (not empty)? Padding; empty: Unknown
  2. 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.
  3. An Exact, complete candidate? Yes: go to 6.
  4. Printable UTF-8? Text
  5. No header candidate complete? Read the bytes as every message's bare body; keep those that use every byte with no evidence against: Inferred.
  6. 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.
  7. 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 characterEncoding is 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.

RuleCheck
H1The header fits in the bytes
H2The wire blockLength fits in the remaining bytes
H3When the wire version is at or above the schema’s, the wire blockLength is at least the schema’s block length
H4Each group dimension fits, numInGroup times its blockLength fits, and each entry’s block fits where the entry starts
H5Each var-data length prefix fits, and so do its bytes
H6A 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.

AgainstFor
An enum value that is neither a valid value nor nullEvery enum holds a valid value or null
A set bit the schema does not defineEvery 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 bytesThe header’s schemaId and templateId were both found
Var data invalid in its declared characterEncodingThe wire version equals the schema version
At the schema’s version, a wire blockLength that differs from the schema’sThe message ends exactly at the end of the bytes
Bytes left after the messageA 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

OrderEvidenceBetter is
1Match classExact, then TemplateOnly, then Inferred
2The walk broke no hard rulecomplete
3Bytes consumedmore
4Evidence againstfewer
5Version distanceequal, then an older writer, then a newer one
  • Candidates equal on all five are Ambiguous, every one listed with its evidence (at most Limits::max_candidates, then a count of the rest).
  • Text loses to an Exact, complete message and beats every other candidate. All-zero bytes are Padding.
  • Inferred bodies 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 fieldDefaultPast it
max_depth8var data deeper than this is Unknown, marked with the depth limit
max_input16 MiBthe whole input is Unknown, marked with the input-size limit
max_candidates8an Ambiguous lists this many and counts the rest
max_walks20 000nothing more is walked; what is left is Unknown, marked with the work limit
max_skip64the 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.