Re: [protobuf] problems with CopyFrom(dynamic message) to generated message

2011-01-26 Thread Richard Spooner
Thanks.

Perhaps I should explain my use case a little better.

I have a proto file which is compiled in, for example known.proto

message KnownMessage
{
// more stuff here
}


I also have another proto file which is not compiled in, for example
unknown.proto

import "known.proto";
message UnknownMessage
{
optional KnownMessage known = 1;
// more stuff here
}


What I am trying to do is reflect on a message of type UnknownMessage
looking for messages of type KnownMessage.  If I find a matching field I am
trying to copy out the KnownMessage so I can use the generated classes on
it.

...Richard









On Wed, Jan 26, 2011 at 3:34 AM, Kenton Varda  wrote:

> They need to have exactly the same Descriptor object.  When you create your
> DynamicMessage from the DynamicMessageFactory, pass the Descriptor object
> returned by the generated type's descriptor() or GetDescriptor() method.
>  Don't construct a separate Descriptor manually.
>
> Of course, then the question is, why are you using DynamicMessage if you
> have the generated type compiled in?  Is it because you need to access
> extensions that aren't compiled in?  In that case, you do need
> dynamically-constructed Descriptor objects.  The best way to copy in this
> case is to serialize the message, and then parse it into the other type.
>
> On Mon, Jan 24, 2011 at 1:34 AM, Richard Spooner wrote:
>
>> All...
>>
>> I am having problems using CopyFrom to copy a dynamic message in to a
>> generated message.
>>
>> I get the following:
>>
>> libprotobuf FATAL google/protobuf/reflection_ops.cc:54] CHECK failed:
>> (to->GetDescriptor()) == (descriptor): Tried to merge messages of different
>> types.
>>
>> Using GetTypeName() I can verify that the types are the same.  I can also
>> be sure that both the dynamic and the generated message use the same proto
>> file.
>>
>> Any ideas?  Should it work?
>>
>> ...Richard
>>
>>
>>  --
>> 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.



Re: [protobuf] problems with CopyFrom(dynamic message) to generated message

2011-01-25 Thread Kenton Varda
They need to have exactly the same Descriptor object.  When you create your
DynamicMessage from the DynamicMessageFactory, pass the Descriptor object
returned by the generated type's descriptor() or GetDescriptor() method.
 Don't construct a separate Descriptor manually.

Of course, then the question is, why are you using DynamicMessage if you
have the generated type compiled in?  Is it because you need to access
extensions that aren't compiled in?  In that case, you do need
dynamically-constructed Descriptor objects.  The best way to copy in this
case is to serialize the message, and then parse it into the other type.

On Mon, Jan 24, 2011 at 1:34 AM, Richard Spooner  wrote:

> All...
>
> I am having problems using CopyFrom to copy a dynamic message in to a
> generated message.
>
> I get the following:
>
> libprotobuf FATAL google/protobuf/reflection_ops.cc:54] CHECK failed:
> (to->GetDescriptor()) == (descriptor): Tried to merge messages of different
> types.
>
> Using GetTypeName() I can verify that the types are the same.  I can also
> be sure that both the dynamic and the generated message use the same proto
> file.
>
> Any ideas?  Should it work?
>
> ...Richard
>
>
>  --
> 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.