Hello Adam,
OK, I understand, so I've tried this, but I get an error.
void my_set_value( class healthreport * r, const char * defaultvalue, const google::protobuf::FieldDescriptor * descriptor ) {
auto reflection = r->report->GetReflection();
switch( descriptor->type() ) {
case google::protobuf::FieldDescriptor::TYPE_STRING: {
printf( "REQUESTED TYPE: STRING" EOL );
std::string s = defaultvalue;
reflection->SetString( r->report, descriptor, s );
}
break;
default:
printf( "REQUESTED TYPE %d NOT HANDLED" EOL, descriptor->type() );
break;
}
}
Running the above produces the following output:
REQUESTED TYPE: STRING
[libprotobuf FATAL /var/tmp/portage/dev-libs/protobuf-3.15.8/work/protobuf-3.15.8/src/google/protobuf/generated_message_reflection.cc:111] Protocol Buffer reflection usage error:
Method : google::protobuf::Reflection::SetString
Message type: vafmsg.HealthReport
Field : vafmsg.HardwareComponent.hardware_interface
Problem : Field does not match message type.
terminate called after throwing an instance of 'google::protobuf::FatalException'
what(): Protocol Buffer reflection usage error:
Method : google::protobuf::Reflection::SetString
Message type: vafmsg.HealthReport
Field : vafmsg.HardwareComponent.hardware_interface
Problem : Field does not match message type.
Here is the proto definition of the variable triggering the exception:
message HardwareComponent {
optional Component component = 1;
repeated DiscreteValue temp = 2;
optional string hardware_interface = 3;
optional uint32 remaining_life = 4;
optional uint32 total_hours = 5;
optional EnergyInfo energy = 6;
}
So the type really IS string, yet an exception is triggered...
What am I doing wrong?