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

Function ProtoMessageToProtoJson

src/json2pb/pb_to_json.cpp:410–435  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

408}
409
410bool ProtoMessageToProtoJson(const google::protobuf::Message& message,
411 google::protobuf::io::ZeroCopyOutputStream* json,
412 const Pb2ProtoJsonOptions& options, std::string* error) {
413 if (ExceedMaxDepth(message, 0)) {
414 if (error) {
415 *error = "Exceeded maximum recursion depth";
416 }
417 return false;
418 }
419 butil::IOBuf buf;
420 butil::IOBufAsZeroCopyOutputStream output_stream(&buf);
421 if (!message.SerializeToZeroCopyStream(&output_stream)) {
422 return false;
423 }
424
425 TypeResolverUniqueptr type_resolver = GetTypeResolver(message);
426 butil::IOBufAsZeroCopyInputStream input_stream(buf);
427 auto st = google::protobuf::util::BinaryToJsonStream(
428 type_resolver.get(), GetTypeUrl(message), &input_stream, json, options);
429
430 bool ok = st.ok();
431 if (!ok && NULL != error) {
432 *error = st.ToString();
433 }
434 return ok;
435}
436
437bool ProtoMessageToProtoJson(const google::protobuf::Message& message, std::string* json,
438 const Pb2ProtoJsonOptions& options, std::string* error) {

Callers 3

TEST_FFunction · 0.50
TEST_FFunction · 0.50

Calls 6

ExceedMaxDepthFunction · 0.85
GetTypeResolverFunction · 0.85
GetTypeUrlFunction · 0.85
okMethod · 0.80
getMethod · 0.45
ToStringMethod · 0.45

Tested by 3

TEST_FFunction · 0.40
TEST_FFunction · 0.40