Skip to content

Write and read proto2 groups in Google's wire format - #311

Open
quinnj-bot[bot] wants to merge 5 commits into
masterfrom
claude/group-wire-format
Open

quinnj-bot[bot] wants to merge 5 commits into
masterfrom
claude/group-wire-format

Conversation

@quinnj-bot

@quinnj-bot quinnj-bot Bot commented Nov 19, 2026 •

Copy link
Copy Markdown
Contributor

Why

proto2 groups (and editions' delimited encoding) end with an END_GROUP tag that carries the group's field number. ProtoBuf.jl wrote a bare 0x04 (field 0) and only recognized that byte. As a result:

  • Google's parsers can't read groups written by ProtoBuf.jl.
  • Decoding a group written by Google fails with Encountered END_GROUP wiretype while skipping. This also hits proto2 readers that skip an unknown group field, for example an older schema reading newer data.
  • Encoding a message whose repeated group field is empty throws AssertionError: !(isempty(x)).
  • A group inside a oneof is written as a length-delimited message, which neither Google nor ProtoBuf.jl reads back as the group.
  • _encoded_size miscounts groups, so the length prefix of a message that contains a group can be wrong when encoding to a non-IOBuffer stream.

What changed

  • encode(e, i, x, Val{:group}) writes the END_GROUP tag with field number i, and an empty vector of groups writes nothing.
  • The decoder ends a group (and skips an unknown group) at any tag whose wire type is END_GROUP, so data written by earlier ProtoBuf.jl versions still decodes.
  • _encoded_size(x, i, Val{:group}) counts two tags plus the content. Generated _encoded_size methods now pass Val{:group} for group fields, and generated oneof code encodes and sizes group members as groups.

Scope

  • Generated code changes for group fields (_encoded_size) and for oneofs that contain groups. Code generated by earlier versions keeps working for decoding and for encoding to an IOBuffer; regenerating fixes the size of group fields.
  • END_GROUP field numbers are not checked against the START_GROUP field number (Google rejects a mismatch).

Blast Radius

Changes the bytes written for every group: the end tag now matches Google's. ProtoBuf.jl readers from before this change will fail to read those groups, so readers should upgrade before writers.

Verification

  • New tests fail on master and pass here: end-tag bytes for field numbers 5 and 100, _encoded_size for groups, an empty repeated group, skipping an unknown group, decoding a group through the legacy GroupProtoDecoder path used by code from older versions, and a complex_message.proto round trip against bytes produced by Python google.protobuf (OmniMessage groups, plus a new GroupOneof message).
  • Differential run against Python google.protobuf 7.36.2 (upb), 420 seeded random proto2/proto3 messages with group schemas (optional, repeated, nested, field 100, inside a oneof, nested in another message, and unknown groups): decode failures drop from 134 on master to 71 on this branch, and every remaining failure involves a negative enum value (separate PR). The encode error on empty repeated groups is gone. With this batch's six fixes merged, all group cases match Python's values and bytes.
  • Pkg.test() passes on Julia 1.10, 1.12, and 1.13 (1.13 with Fix CI: allow JET 0.12 and 0.13, drop the retired macOS-14 runner #309's JET compat).

🤖 Generated with Claude Code

@codecov

codecov Bot commented Nov 19, 2026 •

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 94.44%. Comparing base (3b49752) to head (fcf8456).

Additional details and impacted files
@@            Coverage Diff             @@
##           master     #311      +/-   ##
==========================================
+ Coverage   94.18%   94.44%   +0.25%     
==========================================
  Files          25       25              
  Lines        3115     3116       +1     
==========================================
+ Hits         2934     2943       +9     
+ Misses        181      173       -8     

☔ View full report in Codecov by Harness.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

quinnj and others added 3 commits November 19, 2026 08:15
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
A group ends with an END_GROUP tag that carries the group's field number.
ProtoBuf.jl wrote a bare 0x04 (field 0) and only recognized that byte, so:

- Google's parsers could not read groups written by ProtoBuf.jl.
- Decoding a group written by Google failed with "Encountered END_GROUP
  wiretype while skipping", including unknown groups that should be skipped.
- Encoding a message with an empty repeated group threw an AssertionError.
- A group inside a oneof was written as a length-delimited message.
- `_encoded_size` miscounted groups, so a length prefix written to a
  non-IOBuffer stream could be wrong.

The encoder now writes the END_GROUP tag with the field number. The decoder
accepts any END_GROUP tag at the end of a group, so data written by earlier
versions still decodes. Generated `_encoded_size` methods pass Val{:group},
and generated oneof code encodes group members as groups.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Code generated by ProtoBuf.jl before the decode signature change still
decodes groups through GroupProtoDecoder; it now ends a group at an
END_GROUP tag with any field number too.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@quinnj-bot
quinnj-bot Bot force-pushed the claude/group-wire-format branch from a5fcca5 to a1290bf Compare November 19, 2026 15:15
quinnj and others added 2 commits November 21, 2026 20:33
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>

This branch has not been deployed

No deployments
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.

1 participant