Skip to content

Skip proto3 identity values in reflective adapters - #3752

Open
oldergod wants to merge 3 commits into
masterfrom
bquenaudon/runtime-adapter-proto3-identity
Open

oldergod wants to merge 3 commits into
masterfrom
bquenaudon/runtime-adapter-proto3-identity

Conversation

@oldergod

@oldergod oldergod commented Nov 5, 2026 •

Copy link
Copy Markdown
Member

RuntimeMessageAdapter wrote proto3 implicit-presence fields that hold their identity value, such as 0, "", empty bytes, or the zero enum constant.
Generated adapters and protoc skip these fields.
Java compact = true code, direct reflective adapters, and Schema.protoAdapter() use this path.

encode (with ProtoWriter and ReverseProtoWriter) and encodedSize now skip identity values for scalar and enum fields with the OMIT_IDENTITY label.
proto2 fields, proto3 optional fields, oneof members, and message fields keep their current behavior.
A present wrapper that holds an identity value is still written, as in generated code.
JSON output does not change.

The schema enum adapter had no identity, so Schema.protoAdapter() still wrote a zero enum.
Like generated enum adapters, it now uses the constant with tag 0 as identity.
Schema enum values can be constant names or tags, so the schema binding skips both the zero constant name and 0.

Release note: Java compact = true code, ProtoAdapter.newMessageAdapter, and Schema.protoAdapter now give different bytes for proto3 messages.
They no longer write implicit-presence fields that hold an identity value, so their bytes now match protoc and generated adapters.
The identity of a schema enum adapter is now the name of its constant with tag 0, or null if there is none.

RuntimeMessageAdapter wrote proto3 implicit-presence fields that hold their identity value.
Generated adapters and protoc skip them.

Encode and encodedSize now use the identity check that JSON already uses.
Java compact output now gives the same bytes as generated code.
@oldergod
oldergod marked this pull request as ready for review November 5, 2026 12:37
Schema adapters label proto3 wrapper fields OMIT_IDENTITY, and wrapper adapters expose a scalar identity.
The identity skip dropped present wrappers that hold 0, false, or an empty string.
Generated code writes these wrappers, so the skip now ignores message fields.
@oldergod
oldergod marked this pull request as draft November 5, 2026 12:37
@oldergod
oldergod marked this pull request as ready for review November 5, 2026 13:47
The schema enum adapter had no identity, so a proto3 enum field set to its zero constant was written.
Like generated enum adapters, the schema enum adapter now uses the constant with tag 0 as identity.
The schema binding also treats the tag 0 as the identity, because schema enum values can be names or tags.

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