| 291 | } |
| 292 | |
| 293 | static 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 | |
| 318 | static bool ParseFromJsonValue(const Json::Value& root, Message* pb) { |
| 319 | std::string pb_type = pb->GetTypeName(); |
no test coverage detected