Yes, you should use AddAllocated() in this case. Noted that the ownership of
the object will be passed to the wrapper proto.

On Thu, Apr 21, 2011 at 7:12 AM, Aaron Rich <aaron.r...@gmail.com> wrote:

> I found the method:
> AddAllocated(Element*)
>
> which I think will add the Pong* that I have already created/allocated
> myself.
>
> Any input if there is a better method then this to use would be
> appreciated.
>
> Thanks.
>
> -Aaron
>
> On Wed, Apr 20, 2011 at 4:25 PM, Aaron Rich <aaron.r...@gmail.com> wrote:
> > New to protoco buffers so sorry if this is a simple/stupid question.
> >
> > I have a proto:
> > message WrapperMessage
> > {
> >    enum Type {
> >        PING   = 1;
> >        PONG   = 2;
> >    }
> >
> >    message Header{
> >        required Type   type = 1;
> >        required string source = 2;
> >        required int64  time = 3;
> >    }
> >
> >    required TIMIHeader header = 1;
> >    repeated Ping ping= 2;
> >    repeated Pong pong= 3;
> >    extensions 500 to max;
> > }
> >
> > message Pong
> > {
> >  optional int32 count =1;
> >  optional string message = 2;
> > }
> >
> > message Ping
> > {
> >  optional int32 count =1;
> >  optional string message = 2;
> > }
> >
> >
> > I need the wrapper so that I can send multiple other message types
> > over a single udp datastream. I was going to make a message factory to
> > generate the Ping and Pong messages:
> > Pong* pong = myFactory->createPong("Hello");
> >
> > How can I add this Pong message now to a wrapper? I want to be able to
> > use the factory so I can generate several Pong messages at once to
> > pack together in a single WrapperMessage before sending. I only see
> > that calling:
> > WrapperMessage.add_pong()
> >
> > will give me a Pong* back. But then I either have to merge that will
> > my factory message or pass it to factory to populate.
> >
> > Any suggestions of better way to do this (or improve my proto design)?
> >
> > Thanks.
> >
> > -Aaron
> >
>
> --
> 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.
>
>

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