[Rust] MessageRegistry::from_descriptors for sibling/imported types (PR #461 feedback)#1
Open
pixie79 wants to merge 2 commits into
Open
[Rust] MessageRegistry::from_descriptors for sibling/imported types (PR #461 feedback)#1pixie79 wants to merge 2 commits into
pixie79 wants to merge 2 commits into
Conversation
…mported types MessageRegistry::from_descriptor recurses only nested_type, so it registers the root message and its nested children but never the sibling or imported top-level messages from other files in a FileDescriptorSet. A root field typed e.g. `.google.protobuf.StringValue` (from google/protobuf/wrappers.proto) therefore misses on registry.get() and parsing fails with `UnknownTypeName: Unknown message type '.google.protobuf.StringValue' not in registry` on every record that populates such a field. Add `from_descriptors(root, others)` which keeps the root as the parse root (unchanged from_descriptor behaviour) and additionally registers every other top-level message under its TRUE package-qualified FQN with a leading dot, by threading the proto package as the initial prefix through the existing collector. `collect_messages` now delegates to a `collect_messages_with_prefix` helper so the prefix-threading is shared; the public `from_descriptor` API is byte-for-byte unchanged. Includes unit tests covering sibling registration under a non-empty package, the empty-package (root-prefix) case, and nested-type collection on siblings. Signed-off-by: Mark Olliver <mark.olliver@flutter.com>
Borrow the package strings in the from_descriptors API (`others: &[(&str, &DescriptorProto)]`), trim the verbose rustdoc to a concise summary, and update the two unit-test call sites. Add true end-to-end coverage: create_registry_for_version now builds the registry via from_descriptors, threading every top-level message in the compiled FileDescriptorSet (including the imported google.protobuf types) under its package-qualified FQN. The former negative test test_google_protobuf_types_not_in_registry becomes test_google_protobuf_types_decode_success, decoding a GoogleProtobufTypesMessage and asserting Timestamp, Duration and every wrapper type resolve and decode correctly for both proto2 and proto3. Add a NEXT_CHANGELOG entry for the new zeroparser API. Co-Authored-By: Claude <noreply@anthropic.com> Signed-off-by: Mark Olliver <mark.olliver@flutter.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.
Summary
Adds
MessageRegistry::from_descriptors(behind thezeroparserfeature) and addresses the review feedback from upstream databricks/zerobus-sdk#461.from_descriptoronly recursesnested_type, so it registers the root and its nested children but never the sibling/imported top-level messages from other files in aFileDescriptorSet. A root field typed e.g..google.protobuf.StringValuethen misses onregistry.get()and decode fails withUnknownTypeName.from_descriptors(root, others)closes that gap by additionally registering each other top-level message under its true package-qualified FQN.Feedback addressed
create_registry_for_versionnow builds the registry viafrom_descriptors, threading every top-level message in the compiledFileDescriptorSet(including the importedgoogle.protobuftypes) under its package-qualified FQN. The former negative testtest_google_protobuf_types_not_in_registryis replaced bytest_google_protobuf_types_decode_success, which decodes aGoogleProtobufTypesMessageand assertsTimestamp,Duration, and every wrapper type (StringValue,Int32Value,Int64Value,UInt32Value,UInt64Value,FloatValue,DoubleValue,BoolValue,BytesValue) plusrepeated Timestampresolve and decode correctly — for both proto2 and proto3, using the real descriptor-set path.others: &[(&str, &DescriptorProto)]; call sites/tests updated.from_descriptorsis reduced to a concise summary.Tests
Benchmark evidence
The change touches only
from_descriptorsand the test-only registry helper — none of it is in the benchmark's decodeb.iterloop, so no code-attributable change is expected. The comparison confirms this: all three decoders (prost,prost_reflect, andzeroparser) moved together by a uniform ~40–50% between the two runs, the signature of environmental variance (the base run executed under higher load) rather than a real effect on the byte-identical parser hot path. Net: no regression in the parser.🤖 Generated with Claude Code