import "google/protobuf/descriptor.proto";
message Test {
extend google.protobuf.MessageOptions {
optional int custom_option = 50000;
}
message Nested {
option (custom_option) = 5; }
} If I want, I can compile this to Python. Then in my plugin I can import that Test_pb2.py file and lookup the option:
var.options.Extensions[Test.custom_option]
This works fine. However, the problem I can't figure out is that I need to design the plugin so it works with *any* input file with *any* declared extension option. So I can't write my code as 'Test.custom_option' because I don't know beforehand what options will be declared.
I can get the extension dynamically from the Descriptor.extension list. But this is a FieldDescriptorProto and to look up the extension in options.Extensions I need an 'extension handle'. I'm not sure what that is or how to get it.
name: "Test"
nested_type {
name: "Nested"
options {
}
}
extension {
name: "custom_option"
extendee: ".google.protobuf.MessageOptions"
number: 50000
label: LABEL_OPTIONAL
type: TYPE_INT32
}