Thanks for your reply.
My application links against all the stub proto sources of the types I will
be creating. What I've found works is if I use the default(?) descriptor
pool (google::protobuf::DescriptorPool::generated_pool()) and the default
message factory (google::protobuf::MessageFactory::generated_factory()).
Given the type name and the content, I have a simple function that more or
less does this:
const gpb::Descriptor* descriptor =
gpb::MessageFactory* factory = gpb::MessageFactory::generated_factory();
const gpb::Message* prototype = factory->GetPrototype( descriptor );
gpb::Message* message = prototype->New();
gpb::Message* m = gpb::TextFormat::ParseFromString( "blah: \"some string\"
bleh: 3", message );
On Wednesday, January 16, 2013 4:15:53 PM UTC-8, m wrote:
> Hi All,
> I'm seeing an incompatibility between a dynamically generated
> google::protobuf::Message (DynamicMessage?) created with a
> google::protobuf::DynamicMessageFactory and a normal
> What I'm running up against ultimately comes down to this: I can't
> dynamic_cast a DynamicMessage to a known derived type of
> google::protobuf::Message. For example, let's say my proto file has the
> following message:
> package my.package;
> messsage Foo
> string blah = 1;
> uint32 bleh = 2;
> and I successfully create a my::package::Foo with some code along the
> lines of:
> const google::protobuf::Descriptor* descriptor =
> "my.package.Foo" );
> google::protobuf::Message* message = myDynamicMessageFactory.GetPrototype(
> descriptor )->New();
> after populating message successfully with other commands not shown here,
> I try to do something like:
> my::package::Foo foo;
> foo.CopyFrom( *message );
> and I get a segfault in CopyFrom() because ultimately the following
> doesn't work (the pointer pFoo ends up being NULL down inside
> my::package::Foo* pFoo = dynamic_cast< my::package::Foo* >( message );
> It appears as though the derived type of message is not actually
> my::package::Foo, but instead google::protobuf::DynamicMessage (or
> something like that), so naturally the dynamic_cast fails. I was sure to
> observe the output of message->DebugString() and message->GetTypeName()
> which returned all the appropriate information.
> Is there any way to get a real my::package::Foo object from a dynamic one?
You received this message because you are subscribed to the Google Groups
"Protocol Buffers" group.
To view this discussion on the web visit
To post to this group, send email to email@example.com.
To unsubscribe from this group, send email to
For more options, visit this group at