| 233 | } |
| 234 | |
| 235 | static bool SetRepeatedValueForMessage(const Reflection* reflection, |
| 236 | Message* pb, |
| 237 | const FieldDescriptor* field, |
| 238 | const Json::Value& sub_node) { |
| 239 | switch (field->cpp_type()) { |
| 240 | case FieldDescriptor::CPPTYPE_INT32: |
| 241 | reflection->AddInt32(pb, field, sub_node.asInt()); |
| 242 | break; |
| 243 | case FieldDescriptor::CPPTYPE_INT64: { |
| 244 | int64_t number = 0; |
| 245 | if (!toft::StringToNumber(sub_node.asString(), &number)) { |
| 246 | LOG(WARNING) << "Fail to convert to interger:" << sub_node.asString(); |
| 247 | return false; |
| 248 | } |
| 249 | reflection->AddInt64(pb, field, number); |
| 250 | break; |
| 251 | } |
| 252 | case FieldDescriptor::CPPTYPE_UINT32: |
| 253 | reflection->AddUInt32(pb, field, sub_node.asUInt()); |
| 254 | break; |
| 255 | case FieldDescriptor::CPPTYPE_UINT64: { |
| 256 | uint64_t number = 0; |
| 257 | if (!toft::StringToNumber(sub_node.asString(), &number)) { |
| 258 | LOG(WARNING) << "Fail to convert to interger:" << sub_node.asString(); |
| 259 | return false; |
| 260 | } |
| 261 | reflection->AddUInt64(pb, field, number); |
| 262 | break; |
| 263 | } |
| 264 | case FieldDescriptor::CPPTYPE_DOUBLE: |
| 265 | reflection->AddDouble(pb, field, sub_node.asDouble()); |
| 266 | break; |
| 267 | case FieldDescriptor::CPPTYPE_FLOAT: |
| 268 | reflection->AddFloat(pb, field, sub_node.asDouble()); |
| 269 | break; |
| 270 | case FieldDescriptor::CPPTYPE_BOOL: |
| 271 | reflection->AddBool(pb, field, sub_node.asBool()); |
| 272 | break; |
| 273 | case FieldDescriptor::CPPTYPE_ENUM: { |
| 274 | const EnumValueDescriptor* enum_value = reflection->GetEnum(*pb, field); |
| 275 | const EnumDescriptor* enum_desc = enum_value->type(); |
| 276 | const EnumValueDescriptor* real_enum_value = enum_desc->FindValueByNumber(sub_node.asInt()); |
| 277 | reflection->AddEnum(pb, field, real_enum_value); |
| 278 | break; |
| 279 | } |
| 280 | case FieldDescriptor::CPPTYPE_STRING: |
| 281 | reflection->AddString(pb, field, sub_node.asString()); |
| 282 | break; |
| 283 | case FieldDescriptor::CPPTYPE_MESSAGE: |
| 284 | LOG(INFO)<< "Not implemented"; |
| 285 | break; |
| 286 | default: |
| 287 | LOG(FATAL) << "Bad type:" << field->cpp_type(); |
| 288 | break; |
| 289 | } |
| 290 | return true; |
| 291 | } |
| 292 |
no test coverage detected