Suppose we have a file named foo.proto defining a message and a custom option:
syntax = "proto3";
package foo_package;
import "google/protobuf/descriptor.proto";
enum State {
ALPHA = 0;
BETA = 1;
}
extend google.protobuf.FieldOptions {
State baz = 51234;
}
message Foo {
string bar = 1 [ (baz) = ALPHA ];
}
We generate a FileDescriptorSet (from a directory containing google/protobuf/descriptor.proto) for this message via:
protoc -I=. --include_imports -oTMP ./foo.proto
How can I extract baz from a message class instance in this set? The documentation and library (1), (2) suggest something like this might work:
from google.protobuf.descriptor_pb2 import FileDescriptorSet
from google.protobuf.message_factory import GetMessages
with open("TMP", mode="rb") as f:
fds = FileDescriptorSet.FromString(f.read())
messages = GetMessages([file for file in fds.file])
extensions = messages["foo_package.Foo"].DESCRIPTOR.fields_by_name["bar"].GetOptions().Extensions
but the resulting object is empty. #6662 implies using a DescriptorPool should resolve it, but that also doesn't seem to work (empty object, as well).