| 408 | } |
| 409 | |
| 410 | bool 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 | |
| 437 | bool ProtoMessageToProtoJson(const google::protobuf::Message& message, std::string* json, |
| 438 | const Pb2ProtoJsonOptions& options, std::string* error) { |