On Wed, Oct 25, 2017 at 5:38 AM, <shiyw...@redhat.com> wrote:

> the example in https://developers.google.com/protocol-buffers/docs/
> proto#customoptions below
>
> message FooOptions {
>   optional int32 opt1 = 1;
>   optional string opt2 = 2;
> }
>
> extend google.protobuf.FieldOptions {
>   optional FooOptions foo_options = 1234;
> }
>
> // usage:
> message Bar {
>   optional int32 a = 1 [(foo_options).opt1 = 123, (foo_options).opt2 = "baz"];
>   // alternative aggregate syntax (uses TextFormat):
>   optional int32 b = 2 [(foo_options) = { opt1: 456 opt2: "xaa" }];
> }
>
> assume I have a message Bar here:
>
> var msg Bar
> _, md := ForMessage(&msg)
> md.Field[0].GetOptions().String()  only a string, How do i parse that ??
>
> How to I get the exact value of Bar.b.opt1 which is 123 (default value)
>
> What I want is like this
>
> md.Field[0].GetOptions().GetOpt1()   // 123
> md.Field[0].GetOptions().GetOpt2()    // baz
> md.Field[1].GetOptions().GetOpt1()   // 456
> md.Field[1].GetOptions().GetOpt2()   // xaa
>
> Can we achieve that ?
>
The exact API to access custom options is language specific, It generally
uses the same syntax as accessing extensions. For go, you can post the
question to https://github.com/golang/protobuf


> --
> 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 protobuf+unsubscr...@googlegroups.com.
> To post to this group, send email to protobuf@googlegroups.com.
> Visit this group at https://groups.google.com/group/protobuf.
> For more options, visit https://groups.google.com/d/optout.
>

-- 
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 protobuf+unsubscr...@googlegroups.com.
To post to this group, send email to protobuf@googlegroups.com.
Visit this group at https://groups.google.com/group/protobuf.
For more options, visit https://groups.google.com/d/optout.

Reply via email to