| 295 | } |
| 296 | |
| 297 | static 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 | |
| 318 | static bool ProtoJsonToProtoMessage(const butil::IOBuf& body, |
| 319 | google::protobuf::Message* message, |
no test coverage detected