Thank you, problem solved !!

On Thu, Oct 26, 2017 at 9:57 PM, Josh Humphries <jh...@bluegosling.com>
wrote:

> It works fine when I run it.
>
> > *go test -v .*
> === RUN   TestABCMessage
> opt1:123 opt2:"baz"
> --- PASS: TestABCMessage (0.00s)
> PASS
> ok  test 0.007s
>
>
>
> However, your test file was incomplete. Maybe you have imported the wrong
> stuff? Double-check that you are linking against the latest version of the
> github.com/golang/protobuf packages.
> I had to add imports, and I also changed the handling of the output since
> I don't know what "spew" is:
>
>
>
> package cmd
>
> import (
>   "fmt"
>   "testing"
>
>   "github.com/golang/protobuf/descriptor"
>   "github.com/golang/protobuf/proto"
> )
>
> func TestABCMessage(t *testing.T) {
>    var msg Bar
>
>    _, md := descriptor.ForMessage(&msg)
>
>    opts := md.Field[0].GetOptions()
>    foo, err := proto.GetExtension(opts, E_FooOptions)
>    if err != nil {
>       t.Errorf("failed: %v", err)
>   } else {
>       fmt.Println(foo)
>    }
> }
>
>
>
> ----
> *Josh Humphries*
> jh...@bluegosling.com
>
> On Wed, Oct 25, 2017 at 10:54 PM, <shiyw...@redhat.com> wrote:
>
>> /tmp/TestABCMessage_in_version_abc_test_gogo -test.v -test.run
>> ^TestABCMessage$
>> (*errors.errorString)(0xc420214af0)(proto: not an extendable proto)
>> (interface {}) <nil>
>>
>> On Wednesday, October 25, 2017 at 8:38:51 PM UTC+8, shiy...@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 ?
>>>
>> --
>> 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.
>>
>
>


-- 
Quality Engineer
Red Hat Software (Beijing) Co.,Ltd
IRC: shiywang
Email: shiyw...@redhat.com
10/F, North Tower C, Raycom Infotech Park
No. 2 Ke Xueyuan Nanlu, Haidian District Beijing 100190

-- 
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