I believe the issue has come down to, I'm finding a different
"google/protobuf/any.proto" indirectly via the Importer than I am compiling
against (I've used protoc to generate any.pb.cc and then compiled that
alongside my source). how can I make sure these are the same version?
On Wednesday, September 25, 2024 at 10:26:59 PM UTC-7 Phil Dougherty wrote:
> 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/09e7dea3-5335-4ae3-aa9c-346a0d81420cn%40googlegroups.com.