MCPcopy Create free account
hub / github.com/chen3feng/toft / SetValueForMessage

Function SetValueForMessage

encoding/proto_json_format.cpp:293–316  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

291}
292
293static bool SetValueForMessage(const std::string& field_name,
294 const Json::Value& value,
295 Message* pb) {
296 const Reflection* reflection = pb->GetReflection();
297 const Descriptor* descriptor = pb->GetDescriptor();
298 const FieldDescriptor* field = descriptor->FindFieldByName(field_name);
299 if (field == NULL) {
300 LOG(ERROR) << "No field:" << field_name << ", type:" << pb->GetTypeName();
301 return false;
302 }
303 if (field->is_repeated()) {
304 if (value.type() != Json::arrayValue) {
305 LOG(INFO) << "Expect array, but real time is:" << value.type();
306 return false;
307 }
308 Json::Value::const_iterator it = value.begin();
309 for (; it != value.end(); ++it) {
310 SetRepeatedValueForMessage(reflection, pb, field, *it);
311 }
312 return true;
313 } else {
314 return SetSingleValueForMessage(reflection, pb, field, value);
315 }
316}
317
318static bool ParseFromJsonValue(const Json::Value& root, Message* pb) {
319 std::string pb_type = pb->GetTypeName();

Callers 1

ParseFromJsonValueFunction · 0.85

Calls 4

SetSingleValueForMessageFunction · 0.85
beginMethod · 0.45
endMethod · 0.45

Tested by

no test coverage detected