problems with CopyFrom(dynamic message) to generated message

1,154 views
Skip to first unread message

Richard Spooner

unread,
Jan 24, 2011, 4:34:06 AM1/24/11
to prot...@googlegroups.com
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


Kenton Varda

unread,
Jan 25, 2011, 9:34:34 PM1/25/11
to Richard Spooner, prot...@googlegroups.com
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.



--
You received this message because you are subscribed to the Google Groups "Protocol Buffers" group.
To post to this group, send email to prot...@googlegroups.com.
To unsubscribe from this group, send email to protobuf+u...@googlegroups.com.
For more options, visit this group at http://groups.google.com/group/protobuf?hl=en.

Richard Spooner

unread,
Jan 26, 2011, 4:54:25 AM1/26/11
to Kenton Varda, prot...@googlegroups.com
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
Reply all
Reply to author
Forward
0 new messages