| 30 | static bool ParseFromJsonValue(const Json::Value& root, Message* pb); |
| 31 | |
| 32 | static void CreateNode(const FieldDescriptor* field, |
| 33 | const Reflection* reflection, |
| 34 | const Message& message, |
| 35 | Json::Value* node) { |
| 36 | switch (field->cpp_type()) { |
| 37 | case FieldDescriptor::CPPTYPE_INT32: |
| 38 | (*node)[field->name()] = reflection->GetInt32(message, field); |
| 39 | break; |
| 40 | case FieldDescriptor::CPPTYPE_INT64: |
| 41 | (*node)[field->name()] = toft::IntegerToString(reflection->GetInt64(message, field)); |
| 42 | break; |
| 43 | case FieldDescriptor::CPPTYPE_UINT32: |
| 44 | (*node)[field->name()] = reflection->GetUInt32(message, field); |
| 45 | break; |
| 46 | case FieldDescriptor::CPPTYPE_UINT64: |
| 47 | (*node)[field->name()] = toft::IntegerToString(reflection->GetUInt64(message, field)); |
| 48 | break; |
| 49 | case FieldDescriptor::CPPTYPE_DOUBLE: |
| 50 | (*node)[field->name()] = reflection->GetDouble(message, field); |
| 51 | break; |
| 52 | case FieldDescriptor::CPPTYPE_FLOAT: |
| 53 | (*node)[field->name()] = reflection->GetFloat(message, field); |
| 54 | break; |
| 55 | case FieldDescriptor::CPPTYPE_BOOL: |
| 56 | (*node)[field->name()] = reflection->GetBool(message, field); |
| 57 | break; |
| 58 | case FieldDescriptor::CPPTYPE_ENUM: |
| 59 | (*node)[field->name()] = reflection->GetEnum(message, field)->number(); |
| 60 | break; |
| 61 | case FieldDescriptor::CPPTYPE_STRING: |
| 62 | (*node)[field->name()] = reflection->GetString(message, field); |
| 63 | break; |
| 64 | case FieldDescriptor::CPPTYPE_MESSAGE: |
| 65 | CHECK(false)<< "not reachable"; |
| 66 | break; |
| 67 | default: |
| 68 | CHECK(false) << "bad type:" << field->cpp_type(); |
| 69 | break; |
| 70 | } |
| 71 | } |
| 72 | |
| 73 | static void CreateNodeOfRepeatedField(const FieldDescriptor* field, |
| 74 | const Reflection* reflection, |
no test coverage detected