You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
in c++ i can get the value with name like this:
const auto reflection = pMessage->GetReflection();
std::vector<const FieldDescriptor*> fields;
pMessage->GetReflection()->ListFields(pMessage, &fields);
const auto fieldIter = std::find_if(fields.cbegin(), fields.cend(),
[&lcFieldName](const FieldDescriptor next) {
return boost::iequals(next->name(), lcFieldName);
});
if (fieldIter != fields.cend()) {
std::string result;
auto fieldDescriptor = *fieldIter;
if (!fieldDescriptor->is_repeated()) {
switch (fieldDescriptor->cpp_type()) {
case FieldDescriptor::CPPTYPE_INT32:
result = std::to_string(reflection->GetInt32 (
*pMessage, fieldDescriptor));
break;
case FieldDescriptor::CPPTYPE_INT64:
result = std::to_string(reflection->GetInt64 (
*pMessage, fieldDescriptor));
break;
case FieldDescriptor::CPPTYPE_UINT32:
result = std::to_string(reflection->GetUInt32 (
*pMessage, fieldDescriptor));
break;
case FieldDescriptor::CPPTYPE_UINT64:
result = std::to_string(reflection->GetUInt64 (
*pMessage, fieldDescriptor));
break;
case FieldDescriptor::CPPTYPE_DOUBLE:
result = std::to_string(reflection->GetDouble (
*pMessage, fieldDescriptor));
break;
case FieldDescriptor::CPPTYPE_FLOAT:
result = std::to_string(reflection->GetFloat (
*pMessage, fieldDescriptor));
break;
...
}
is there any api like GetFloat which can be used to get the message field value?
Unfortunately not. What you are asking for is called protobuf reflection, which does not exist in the current API. There is a new major re-implementation of Go protobufs underway that should be released in the upcoming months. It's flagship feature is protobuf reflection.
No description provided.
The text was updated successfully, but these errors were encountered: