MCPcopy Create free account
hub / github.com/apache/impala / ProtobufToJson

Function ProtobufToJson

be/src/util/json-util.cc:102–164  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

100}
101
102void ProtobufToJson(const google::protobuf::Message& pb, Document* document, Value* obj) {
103 const google::protobuf::Reflection* reflection = pb.GetReflection();
104 vector<const google::protobuf::FieldDescriptor*> fields;
105 reflection->ListFields(pb, &fields);
106 for (const google::protobuf::FieldDescriptor* field : fields) {
107 if (field->is_repeated()) {
108 RepeatedFieldToJson(pb, reflection, field, document, obj);
109 continue;
110 }
111 Value field_name(field->name(), document->GetAllocator());
112 switch (field->cpp_type()) {
113 case google::protobuf::FieldDescriptor::CPPTYPE_INT32:
114 obj->AddMember(
115 field_name, reflection->GetInt32(pb, field), document->GetAllocator());
116 break;
117 case google::protobuf::FieldDescriptor::CPPTYPE_INT64:
118 obj->AddMember(
119 field_name, reflection->GetInt64(pb, field), document->GetAllocator());
120 break;
121 case google::protobuf::FieldDescriptor::CPPTYPE_UINT32:
122 obj->AddMember(
123 field_name, reflection->GetUInt32(pb, field), document->GetAllocator());
124 break;
125 case google::protobuf::FieldDescriptor::CPPTYPE_UINT64:
126 obj->AddMember(
127 field_name, reflection->GetUInt64(pb, field), document->GetAllocator());
128 break;
129 case google::protobuf::FieldDescriptor::CPPTYPE_FLOAT:
130 obj->AddMember(
131 field_name, reflection->GetFloat(pb, field), document->GetAllocator());
132 break;
133 case google::protobuf::FieldDescriptor::CPPTYPE_DOUBLE:
134 obj->AddMember(
135 field_name, reflection->GetDouble(pb, field), document->GetAllocator());
136 break;
137 case google::protobuf::FieldDescriptor::CPPTYPE_BOOL:
138 obj->AddMember(
139 field_name, reflection->GetBool(pb, field), document->GetAllocator());
140 break;
141 case google::protobuf::FieldDescriptor::CPPTYPE_ENUM: {
142 Value enum_str(
143 reflection->GetEnum(pb, field)->name(), document->GetAllocator());
144 obj->AddMember(field_name, enum_str, document->GetAllocator());
145 break;
146 }
147 case google::protobuf::FieldDescriptor::CPPTYPE_STRING: {
148 string str = reflection->GetString(pb, field);
149 Redact(&str, nullptr);
150 Value val_str(str, document->GetAllocator());
151 obj->AddMember(field_name, val_str, document->GetAllocator());
152 break;
153 }
154 case google::protobuf::FieldDescriptor::CPPTYPE_MESSAGE: {
155 Value child_obj(rapidjson::kObjectType);
156 ProtobufToJson(reflection->GetMessage(pb, field), document, &child_obj);
157 obj->AddMember(field_name, child_obj, document->GetAllocator());
158 break;
159 }

Callers 2

ToJsonMethod · 0.85
RepeatedFieldToJsonFunction · 0.85

Calls 8

RepeatedFieldToJsonFunction · 0.85
RedactFunction · 0.85
is_repeatedMethod · 0.80
GetInt64Method · 0.80
GetMessageMethod · 0.80
nameMethod · 0.45
AddMemberMethod · 0.45
GetStringMethod · 0.45

Tested by

no test coverage detected