[protobuf] c++ extension question

2009-12-31 Thread Wade Berrier
Hi,

Given the following:

--
message MessageContainer {
   optional string common_header_info   = 1 [default = ];
extensions 1000 to max;
}

message SubMessage
{
optional string mySubString = 1;
}

extend MessageContainer
{
optional SubMessage subMessage = 1001;
}

--

If I have a Message* (which is actually a SubMessage), how to I set or
copy that extension into MessageContainer, without knowing that the
Message* is a SubMessage?

It looks like all extensions accessors need to use
ExtensionIdentifiers.  Is the above possible?

The idea is that I'll use MessageContainer to contain one of several
messages that extend MessageContainer, but I want to have generic code
that doesn't have to know what type of Message is being dealt with.
And I want the code that deals with Messages not to have to worry
about the MessageContainer message.

Another question: is it possible to set an extension message without
making a copy of the message?  I read a post about MutableExtension
being designed the way it was because object ownership is clear.  But,
I'd hate to have to make a copy if it's not necessary.

Any help/feedback would be greatly appreciated.

Wade

--

You received this message because you are subscribed to the Google Groups 
Protocol Buffers group.
To post to this group, send email to proto...@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.




Re: [protobuf] c++ extension question

2009-12-31 Thread Kenton Varda
If you have the FieldDescriptor representing the extension, you can use the
container's Reflection interface to do it:

  container.GetReflection()-MutableMessage(container,
descriptor)-CopyFrom(*message);

On Thu, Dec 31, 2009 at 1:41 PM, Wade Berrier wberr...@gmail.com wrote:

 Hi,

 Given the following:

 --
 message MessageContainer {
   optional string common_header_info   = 1 [default = ];
extensions 1000 to max;
 }

 message SubMessage
 {
optional string mySubString = 1;
 }

 extend MessageContainer
 {
optional SubMessage subMessage = 1001;
 }

 --

 If I have a Message* (which is actually a SubMessage), how to I set or
 copy that extension into MessageContainer, without knowing that the
 Message* is a SubMessage?

 It looks like all extensions accessors need to use
 ExtensionIdentifiers.  Is the above possible?

 The idea is that I'll use MessageContainer to contain one of several
 messages that extend MessageContainer, but I want to have generic code
 that doesn't have to know what type of Message is being dealt with.
 And I want the code that deals with Messages not to have to worry
 about the MessageContainer message.

 Another question: is it possible to set an extension message without
 making a copy of the message?  I read a post about MutableExtension
 being designed the way it was because object ownership is clear.  But,
 I'd hate to have to make a copy if it's not necessary.


Nope, you have to copy.  The way to avoid copies is to construct the message
in-place in the first place.



 Any help/feedback would be greatly appreciated.

 Wade

 --

 You received this message because you are subscribed to the Google Groups
 Protocol Buffers group.
 To post to this group, send email to proto...@googlegroups.com.
 To unsubscribe from this group, send email to
 protobuf+unsubscr...@googlegroups.comprotobuf%2bunsubscr...@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 proto...@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.