MCPcopy Create free account
hub / github.com/apache/brpc / ProtoMessageToJson

Function ProtoMessageToJson

src/brpc/policy/http_rpc_protocol.cpp:297–316  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

295}
296
297static bool ProtoMessageToJson(const google::protobuf::Message& message,
298 butil::IOBufAsZeroCopyOutputStream* wrapper,
299 Controller* cntl, int error_code) {
300 json2pb::Pb2JsonOptions options;
301 options.bytes_to_base64 = cntl->has_pb_bytes_to_base64();
302 options.jsonify_empty_array = cntl->has_pb_jsonify_empty_array();
303 options.always_print_primitive_fields = cntl->has_always_print_primitive_fields();
304 options.single_repeated_to_array = cntl->has_pb_single_repeated_to_array();
305 options.enum_option = FLAGS_pb_enum_as_number
306 ? json2pb::OUTPUT_ENUM_BY_NUMBER
307 : json2pb::OUTPUT_ENUM_BY_NAME;
308 std::string error;
309 bool ok = json2pb::ProtoMessageToJson(message, wrapper, options, &error);
310 if (!ok) {
311 cntl->SetFailed(error_code, "Fail to convert %s to json: %s",
312 butil::EnsureString(message.GetDescriptor()->full_name()).c_str(),
313 error.c_str());
314 }
315 return ok;
316}
317
318static bool ProtoJsonToProtoMessage(const butil::IOBuf& body,
319 google::protobuf::Message* message,

Callers 3

SerializeHttpRequestFunction · 0.70
~HttpResponseSenderMethod · 0.70
SerializeRpcMessageFunction · 0.70

Calls 8

EnsureStringFunction · 0.85
SetFailedMethod · 0.45
c_strMethod · 0.45
GetDescriptorMethod · 0.45

Tested by

no test coverage detected