On Jan 9, 1:32 am, chongyc <chongy...@gmail.com> wrote:
> I defined proto by following .
>
> message Ch {
>   required int32        offset = 1;
>
> }
>
> message Foo {
>   required string cmd = 1;
>
>   extensions 1000 to max;
>
> }
>
> message Bar {
>   extend Foo {
>     required Ch ck = 1000;
>   }
>
> }
>
> Then I generated c++ code from it.
> It's OK
>
> I am going to set value to extension ck()
> I compiled c++ source following below.
>
>         term2relay::Foo f;
>         term2relay::Bar b;
>         term2relay::Ch c;
>
>         c.set_offset (100);
>
>        f.SetExtension(Bar::ck, c);
>
> But compiling failed in source code line
>       f.SetExtension(Bar::ck, c);
>
> How to do it ?
>
> Please help me.

You don't need to create a Ch instance yourself - it's done for you
when you create a new Foo instance, which is analogous to the same
situation without extensions, but in this case, you need to get a
mutable pointer to your Ch instance.  Try this:

term2relay::Foo f;
term2relay::Ch* c = f.MutableExtension(Bar::ck);
c->set_offset(100);

You also need to change ck's label to 'optional'; otherwise you get an
assertion error.  Kenton, do all composite fields in extensions have
to be optional?  If so, can we document this?
--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups 
"Protocol Buffers" group.
To post to this group, send email to protobuf@googlegroups.com
To unsubscribe from this group, send email to 
protobuf+unsubscr...@googlegroups.com
For more options, visit this group at 
http://groups.google.com/group/protobuf?hl=en
-~----------~----~----~----~------~----~------~--~---

Reply via email to