Skip to content

sbe: tell two schemas' template ids apart (#134) - #137

Merged
trendvidia merged 3 commits into
mainfrom
sbe-template-lookup-134
Nov 5, 2026
Merged

trendvidia merged 3 commits into
mainfrom
sbe-template-lookup-134

Conversation

@bfrancojr

Copy link
Copy Markdown
Collaborator

Fixes #134.

Two schemas in one codec can now use the same template id without one hiding the other. Before, this port looked a message up by template id alone. A second message with the same id replaced the first, NewView read one schema's bytes as another schema's message, and Unmarshal never compared the header's schema id. Ported from protowire-go #256, #258 and #270 (issues #253, #257).

  • Codec::New refuses two different messages with one (sbe.template_id) in one schema: sbe: messages A and B share (sbe.template_id) = 7 in schema 1; it must be unique within a schema. A file passed twice still binds, and so do two schemas that share an id.
  • NewView looks the template up by the header's schema id and template id. It refuses an unknown pair with sbe: unknown template ID 9 in schema 2; it used to say unknown template id 9.
  • Unmarshal and UnmarshalDescriptor refuse sbe: schema ID mismatch: got 1, want 2 for template 7. The version is not checked.

This narrows what decodes: a caller that builds headers by hand must set the schema id. The CHANGELOG says so.

Stack and merge order: #123 → #124 → this PR → #132's PR → #133's PR. This PR's base is sbe-stale-122 (#124), since both edit Codec::RegisterMessage.

Evidence, at 3e8f6d4, on macOS:

@bfrancojr

Copy link
Copy Markdown
Collaborator Author

Rebased onto main e1c1b72 (#136 merged); head is now c7e097e. The PR's own diff is unchanged, checked by comparing its added and removed lines before and after the rebase. Rebased as part of the SBE stack; evidence is on #123.

A file or message carrying its SBE option at the pre-v1.12.0 number is
reported as stale instead of missing or silently skipped, and the
missing-schema-id error uses Go's words. The check moves to annotations.cc,
shared with ProtoToXML.
A template id is unique only within a schema (draft -01 § SBE
Annotations). The codec keyed messages by template id alone, so a
second message with the same id replaced the first, NewView read one
schema's bytes as another's message, and Unmarshal never compared the
header's schema id.

As protowire-go does (#253, #257):
- Codec::New refuses two different messages with one (sbe.template_id)
  in one schema. The same message registered again is not a duplicate,
  and two schemas that share an id still bind.
- by_id_ is keyed by (schema id, template id); NewView reads the schema
  id from header bytes 4-5 and refuses an unknown pair with
  "sbe: unknown template ID N in schema S".
- Unmarshal and UnmarshalDescriptor refuse a schema id mismatch with
  "sbe: schema ID mismatch: got N, want M for template T".

Tests ported from Go's encoding/sbe/template_id_test.go.
@bfrancojr

Copy link
Copy Markdown
Collaborator Author

Rebased with the stack onto main df6b102; head is now bcedc19. Evidence is on #124.

Base automatically changed from sbe-stale-122 to main November 5, 2026 00:03
@trendvidia
trendvidia merged commit 197e05b into main Nov 5, 2026
11 checks passed
@trendvidia
trendvidia deleted the sbe-template-lookup-134 branch November 5, 2026 00:47
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

sbe: messages are found by template id alone, so two schemas sharing one collide (protowire-go#256, #258, #270)

2 participants