I'm trying to dynamically populate an Any message, and cannot figure out
how I should do it. The code I'm currently working with is this:
google::protobuf::Message* dstmessage; //some existing message with a
google.protobuf.Any in its "myAnyField" member I would like to fill out
const google::protobuf::Descriptor* dstdescriptor =
dstmessage->GetDescriptor();
const google::protobuf::Reflection* dstreflection =
dstmessage->GetReflection();
const google::protobuf::FieldDescriptor* dstfield = dstdescriptor->
FindFieldByName("myAnyField");
google::protobuf::Message* myAnyMessage =
dstreflection->MutableMessage(dstmessage,
dstfield);
//note that here, myAnyMessage->GetDescriptor()->full_name() ==
"google.protobuf.Any"
google::protobuf::Any* myAnyContent = new google::protobuf::Any();
//assume myAnyContent is filled out with data here
google::protobuf::Any* myAnyField =
google::protobuf::DynamicCastToGenerated<google::protobuf::Any>(myAnyMessage);
//myAnyField is null here! the cast failed! why?
myAnyField->MergeFrom(*myAnyContent);
Any tips?
--
You received this message because you are subscribed to the Google Groups
"Protocol Buffers" group.
To unsubscribe from this group and stop receiving emails from it, send an email
to [email protected].
To view this discussion on the web visit
https://groups.google.com/d/msgid/protobuf/dcad447f-f482-4f49-97e8-739c9c6cde2en%40googlegroups.com.