From 28b0153ca76e13fb05951a4efb0cf70085ffbd83 Mon Sep 17 00:00:00 2001 From: aozhiwei Date: Thu, 24 Mar 2022 15:13:31 +0800 Subject: [PATCH] 1 --- cpp/utils.cc | 12 ++++++++++++ cpp/utils.h | 1 + 2 files changed, 13 insertions(+) diff --git a/cpp/utils.cc b/cpp/utils.cc index 1159db2..86ea54c 100644 --- a/cpp/utils.cc +++ b/cpp/utils.cc @@ -9,6 +9,7 @@ #include #include +#include #include "framework/cpp/utils.h" @@ -531,4 +532,15 @@ namespace f8 return true; } + std::string PbToJson(google::protobuf::Message* pbmsg) + { + std::string json; + google::protobuf::util::JsonPrintOptions options; + options.add_whitespace = true; + options.always_print_primitive_fields = true; + options.preserve_proto_field_names = true; + MessageToJsonString(*pbmsg, &json, options).ok(); + return json; + } + } diff --git a/cpp/utils.h b/cpp/utils.h index cd3baf6..583a9d1 100644 --- a/cpp/utils.h +++ b/cpp/utils.h @@ -119,4 +119,5 @@ namespace f8 bool IsTestEnv(); bool IsValidNormalConfig(a8::XObject& conf, std::vector fields); + std::string PbToJson(google::protobuf::Message* pbmsg); }