Newer
Older
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
#include <util/protobuf.hh>
#include <google/protobuf/util/json_util.h>
#include <fmt/core.h>
#include "catch.hpp"
namespace vereign {
namespace test {
std::string ProtobufToJson(const google::protobuf::Message& msg) {
google::protobuf::util::JsonPrintOptions options;
options.preserve_proto_field_names = true;
options.always_print_primitive_fields = true;
options.always_print_enums_as_ints = true;
options.add_whitespace = true;
std::string json;
auto status = google::protobuf::util::MessageToJsonString(
msg,
&json,
options
);
if (!status.ok()) {
FAIL(
fmt::format(
"request json encode failed: {}",
std::string(status.error_message())
)
);
}
return json;
}
} // namespace vereign
} // namespace test