7 #include "packager/media/base/proto_json_util.h" 9 #include <google/protobuf/util/json_util.h> 11 #include "packager/base/logging.h" 16 std::string MessageToJsonString(
const google::protobuf::Message& message) {
17 google::protobuf::util::JsonPrintOptions json_print_options;
18 json_print_options.preserve_proto_field_names =
true;
21 GOOGLE_CHECK_OK(google::protobuf::util::MessageToJsonString(
22 message, &result, json_print_options));
26 bool JsonStringToMessage(
const std::string& input,
27 google::protobuf::Message* message) {
28 google::protobuf::util::JsonParseOptions json_parse_options;
29 json_parse_options.ignore_unknown_fields =
true;
31 auto status = google::protobuf::util::JsonStringToMessage(input, message,
34 LOG(ERROR) <<
"Failed to parse from JSON: " << input
35 <<
" error: " << status.error_message();
All the methods that are virtual are virtual for mocking.