couldn't figure this out. the workaround I came up with was:
- populate the message by setting its "type_url" and "value" fields
explicitly with the reflection API
- populate an any via its .set_type_url()/.set_value() functions with
content harvested from the message via its reflection "getString" on those
fields
tl;dr: manually piece-wise copy the values from one form to the other
On Thursday, September 26, 2024 at 8:50:32 AM UTC-7 Phil Dougherty wrote:
> 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/c0c38fc5-6ed4-4e36-b72a-30fac49a4817n%40googlegroups.com.