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

Method WriteToValue

encoding/proto_json_format.cpp:117–156  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

115}
116
117bool ProtoJsonFormat::WriteToValue(const Message& message, Json::Value* root) {
118 const Reflection* reflection = message.GetReflection();
119 Json::FastWriter writer;
120 std::vector<const FieldDescriptor*> fields;
121 reflection->ListFields(message, &fields);
122
123 for (size_t i = 0; i < fields.size(); i++) {
124 const FieldDescriptor* field = fields[i];
125 const std::string& field_name = field->name();
126
127 if (field->cpp_type() != FieldDescriptor::CPPTYPE_MESSAGE) {
128 if (field->is_repeated()) {
129 Json::Value node;
130 int field_size = reflection->FieldSize(message, field);
131 for (int k = 0; k < field_size; ++k) {
132 CreateNodeOfRepeatedField(field, reflection, message, k, &node);
133 }
134 (*root)[field_name] = node;
135 } else {
136 CreateNode(field, reflection, message, root);
137 }
138 } else {
139 if (field->is_repeated()) {
140 Json::Value node;
141 for (int i = 0; i < reflection->FieldSize(message, field); ++i) {
142 Json::Value sub_node;
143 const Message& sub_message = reflection->GetRepeatedMessage(message,
144 field, i);
145 WriteToValue(sub_message, &sub_node);
146 node.append(sub_node);
147 }
148 (*root)[field_name] = node;
149 } else {
150 const Message& sub_message = reflection->GetMessage(message, field);
151 WriteToValue(sub_message, &((*root)[field_name]));
152 }
153 }
154 }
155 return true;
156}
157
158bool ProtoJsonFormat::PrintToStyledString(const Message& message, std::string* output) {
159 Json::Value root;

Callers

nothing calls this directly

Calls 3

CreateNodeFunction · 0.85
sizeMethod · 0.45

Tested by

no test coverage detected