Registry
A Registry is a collection of descriptors that enables lookup by name.
It is only needed when working with google.protobuf.Any or extensions in ProtoJSON; everywhere else, descriptors are self-contained.
Creating a registry
Pass file descriptors (or message/enum types) to the constructor:
Or build one incrementally with add():
Looking up types
registry.message("example.User") # DescMessage | None
registry.enum("example.PhoneType") # DescEnum | None
registry.file("example.proto") # DescFile | None
registry.extension("example.sensitive") # DescExtension | None
Using a registry with Any and JSON
Pass the registry when serializing or deserializing messages that contain google.protobuf.Any fields or extensions.
See Any and Extensions and JSON for examples.
Iterating over fields
Iterating over a message yields the DescField of each currently set field; see Working with Messages for details.
The registry pairs naturally with message iteration to build generic tools (serializers, validators, diff tools) that operate on any message type without knowing the concrete type at compile time.