This commit is contained in:
aozhiwei 2022-03-24 15:13:31 +08:00
parent 180f9e3f5c
commit 28b0153ca7
2 changed files with 13 additions and 0 deletions

View File

@ -9,6 +9,7 @@
#include <a8/mutable_xobject.h>
#include <google/protobuf/message.h>
#include <google/protobuf/util/json_util.h>
#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;
}
}

View File

@ -119,4 +119,5 @@ namespace f8
bool IsTestEnv();
bool IsValidNormalConfig(a8::XObject& conf, std::vector<std::string> fields);
std::string PbToJson(google::protobuf::Message* pbmsg);
}