20#include <google/protobuf/message.h>
21#include <google/protobuf/text_format.h>
22#include <google/protobuf/util/json_util.h>
28 std::enable_if_t<std::is_base_of_v<google::protobuf::Message, T>, char>> {
30 constexpr format_parse_context::iterator
parse(format_parse_context& ctx) {
31 auto it = ctx.begin();
32 for (; it != ctx.end() && *it !=
'}'; it++) {
37 format_context::iterator
format(
const T& proto, format_context& ctx)
const {
40 if (!google::protobuf::TextFormat::PrintToString(proto, &
text)) {
41 return fmt::format_to(ctx.out(),
"(proto format error");
43 }
else if (format_ ==
'j') {
44 auto result = google::protobuf::util::MessageToJsonString(proto, &
text);
46 return fmt::format_to(ctx.out(),
"(json error: {})",
47 std::string(result.ToString()));
50 return fmt::format_to(ctx.out(),
"(unknown format specifier)");
52 return fmt::format_to(ctx.out(),
"{}",
text);
static const char *const text[]
Definition: ext2_err.c:10
Definition: logging.h:464