Did you ever figure out a solution for this? I'm running into exactly the
same issue. I can even pull DOCUMENTATION out of the proto file using
source_code_info - but there's nowhere I can look to find the value that
the option is set to.
On Saturday, April 29, 2017 at 11:54:37 PM UTC-4, Robert Dyer wrote:
>
> That would work to find the actual extension. That isn't the problem I am
> having (I can find the extension). The problem is that as an extension
> option, the message containing the option doesn't show it. For example if
> I do a text_format on the pb from inside the plugin I see this:
>
>
> name: "Test"
> nested_type {
>
> name: "Nested"
>
> options {
>
> }
>
> }
> extension {
>
> name: "custom_option"
>
> extendee: ".google.protobuf.MessageOptions"
>
> number: 50000
>
> label: LABEL_OPTIONAL
>
> type: TYPE_INT32
>
> }
>
>
>
> So while it clearly shows an option was set, it isn't listing the option
> value of 5. What I need is to get that value.
>
> Note that I can figure out how to do this if I compile the .proto into
> Python and then hard code the specific types and look up the extension
> option that way. The problem is we wont know the types beforehand and must
> do this inside the protoc plugin as we process the .proto itself.
>
> On Friday, April 28, 2017 at 8:44:01 PM UTC-4, Josh Haberman wrote:
>>
>> Have you tried just using the FieldDescriptor? I suspect that will work,
>> as it's what some of our own code does. For example see:
>>
>>
>> https://github.com/google/protobuf/blob/master/python/google/protobuf/text_format.py#L819
>>
>> On Monday, April 24, 2017 at 8:19:23 PM UTC-7, Robert Dyer wrote:
>>>
>>> I'm writing a protoc plugin for 2.5.0. My plugin is in Python.
>>>
>>> Given the following proto:
>>>
>>> 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.
>>>
>>
--
You received this message because you are subscribed to the Google Groups
"Protocol Buffers" group.
To unsubscribe from this group and stop receiving emails from it, send an email
to [email protected].
To post to this group, send email to [email protected].
Visit this group at https://groups.google.com/group/protobuf.
For more options, visit https://groups.google.com/d/optout.