feat(zeroparser): add MessageRegistry::from_descriptors for sibling/imported types#461
Open
pixie79 wants to merge 2 commits into
Open
feat(zeroparser): add MessageRegistry::from_descriptors for sibling/imported types#461pixie79 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>
7775b1d to
80fcd0b
Compare
brankogrb-db
reviewed
Jul 1, 2026
| /// `root` remains the parse root (`root_descriptor`); the existing | ||
| /// `from_descriptor` API is unchanged. | ||
| #[inline(always)] | ||
| pub fn from_descriptors(root: &DescriptorProto, others: &[(String, &DescriptorProto)]) -> Self { |
Contributor
There was a problem hiding this comment.
Change seems reasonable but let's add e2e tests for it
| } | ||
| } | ||
|
|
||
| /// Build a registry from a root descriptor plus the other top-level message |
Contributor
There was a problem hiding this comment.
let's try to keep comments short and concise.
| /// `root` remains the parse root (`root_descriptor`); the existing | ||
| /// `from_descriptor` API is unchanged. | ||
| #[inline(always)] | ||
| pub fn from_descriptors(root: &DescriptorProto, others: &[(String, &DescriptorProto)]) -> Self { |
Contributor
There was a problem hiding this comment.
use &str instead of String
Contributor
|
Let's also run existing benchmarks to make sure we didn't hit some perf regression - even though we shouldn't |
Contributor
|
Since I see you generated this PR with AI, I suggest running self-review on this PR with AI also. I think it can be super helpful on finding out some of the issues |
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.
What changes are proposed in this pull request?
Add a new constructor,
MessageRegistry::from_descriptors(root, others), to thezeroparserregistry so a parse registry can be built from the wholeFileDescriptorSet— the root message plus the sibling/imported top-levelmessages it references — rather than from the root descriptor alone.
Concretely:
from_descriptors(root: &DescriptorProto, others: &[(String, &DescriptorProto)]).It registers the root exactly as
from_descriptordoes (so root-relativelookups are identical), then registers every other top-level message under its
true package-qualified FQN (leading dot), e.g. package
google.protobuf+message
StringValue→ key.google.protobuf.StringValue. That key matchesthe
type_nameform carried on message-typedFieldDescriptorProtos, sofield lookups now resolve.
collect_messagesnow delegates to a smallcollect_messages_with_prefix(root, initial_prefix, acc)helper that threadsthe enclosing namespace as a prefix. An empty prefix yields
.Name(theexisting root behaviour); a package prefix like
.google.protobufyields.google.protobuf.Name.from_descriptoris unchanged(it simply calls the helper with the root prefix), so all current callers and
semantics are preserved byte-for-byte. The change is purely additive.
Why are these changes needed?
MessageRegistry::from_descriptoronly recursesnested_type. It thereforeregisters the root message and its nested children, but never the sibling
or imported top-level messages that live in other files of the same
FileDescriptorSet.The most common casualty is the Protobuf well-known types. A root message with a
field typed
.google.protobuf.StringValue(imported fromgoogle/protobuf/wrappers.proto) compiles and loads fine, but at parse time thelookup for
.google.protobuf.StringValuemisses the registry and decoding failson every record that populates such a field:
This affects any schema that uses imported messages — the
google.protobufwrappers (
StringValue,Int64Value, …),Timestamp,Duration,Any, or auser's own imported
.prototypes. There is currently no public way to populatethe registry with those sibling/imported descriptors, because the
messagesmapand the collector are private.
from_descriptorsprovides that path withoutdisturbing the existing root-only constructor, so callers that have the full
descriptor set can opt in and decode imported-type fields correctly.
How is this tested?
cargo test -p databricks-zerobus-ingest-sdk --features zeroparser(thezeroparsermodule is feature-gated):zeroparser::registry— 6 passed, 0 failed, including the two new tests:message_registry_from_descriptors_registers_siblings— provesfrom_descriptoralone does not register an imported.google.protobuf.StringValue(lookup isNone), whilefrom_descriptorsregisters it under its true FQN, keeps the root as the parse root, and the
field still resolves to
.google.protobuf.StringValue.message_registry_from_descriptors_empty_package_and_nesting— covers theempty (unnamed) package case (sibling registers at
.Name) and confirms asibling's own nested types are collected (
.Sibling.Inner).zeroparsersuite — 82 passed, 0 failed; the e2e example binarycompiles green.
The change is also exercised downstream (a consumer that builds the registry
from the full
FileDescriptorSetviafrom_descriptors): a record carrying apopulated
StringValueandTimestampon the wire previously failed with theUnknownTypeNameerror above and now decodes and round-trips correctly.Signed-off-by: Mark Olliver mark.olliver@flutter.com