Implement #712: idiomatic protobuf map<K,V> support (read + write) - #719
Open
cowtowncoder wants to merge 3 commits into
Open
Implement #712: idiomatic protobuf map<K,V> support (read + write)#719cowtowncoder wants to merge 3 commits into
map<K,V> support (read + write)#719cowtowncoder wants to merge 3 commits into
Conversation
Maps are encoded on the wire exactly like a `repeated` entry sub-message
(key = tag 1, value = tag 2). This exposes them idiomatically as JSON Objects
in both directions, at streaming and databind levels.
Schema (TypeResolver / ProtobufField): a `map<K,V>` field (or, from a protoc
descriptor set, a `repeated` field whose entry message carries the `map_entry`
option) is resolved into a synthetic entry message plus a repeated, map-flagged
field. Key types are restricted to integral / bool / string.
Generator: a map field is written as a sequence of length-delimited entry
sub-messages; each writeFieldName opens an entry (key rendered from the JSON
field name per the key type) and primes the value field.
Parser: a map surfaces as START_OBJECT + FIELD_NAME(key)/value pairs +
END_OBJECT, mirroring the unpacked-repeated-message machinery (with an entry
context so end-offset tracking survives buffer reloads). Absent key/value decode
to proto3 defaults; a value that precedes the key is reported clearly.
Descriptor path (FileDescriptorSet): propagate the `map_entry` message option so
.desc-loaded maps get the same treatment as .proto ones. NOTE: this changes the
shape of .desc-loaded maps, which previously surfaced as an array of
{key,value} entries.
Also flips the two #708 tests that asserted maps throw, and updates the now-stale
notes in ProtobufSchemaPreprocessor. Schema generation from POJO Map fields
(ProtoBufSchemaVisitor.expectMapFormat) remains unsupported; left for a follow-up.
Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Maps are encoded on the wire exactly like a
repeatedentry sub-message (key = tag 1, value = tag 2). This exposes them idiomatically as JSON Objects in both directions, at streaming and databind levels.Schema (TypeResolver / ProtobufField): a
map<K,V>field (or, from a protoc descriptor set, arepeatedfield whose entry message carries themap_entryoption) is resolved into a synthetic entry message plus a repeated, map-flagged field. Key types are restricted to integral / bool / string.Generator: a map field is written as a sequence of length-delimited entry sub-messages; each writeFieldName opens an entry (key rendered from the JSON field name per the key type) and primes the value field.
Parser: a map surfaces as START_OBJECT + FIELD_NAME(key)/value pairs + END_OBJECT, mirroring the unpacked-repeated-message machinery (with an entry context so end-offset tracking survives buffer reloads). Absent key/value decode to proto3 defaults; a value that precedes the key is reported clearly.
Descriptor path (FileDescriptorSet): propagate the
map_entrymessage option so .desc-loaded maps get the same treatment as .proto ones. NOTE: this changes the shape of .desc-loaded maps, which previously surfaced as an array of {key,value} entries.Also flips the two #708 tests that asserted maps throw, and updates the now-stale notes in ProtobufSchemaPreprocessor. Schema generation from POJO Map fields (ProtoBufSchemaVisitor.expectMapFormat) remains unsupported; left for a follow-up.