aboutsummaryrefslogtreecommitdiffstats
path: root/library/cpp/eventlog/event_field_printer.cpp
blob: 29c6b4b661e4456f81854cf5c3905e8a3e6307eb (plain) (blame)
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
#include "event_field_printer.h"

#include <library/cpp/protobuf/json/proto2json.h>

namespace {

    const NProtobufJson::TProto2JsonConfig PROTO_2_JSON_CONFIG = NProtobufJson::TProto2JsonConfig()
        .SetMissingRepeatedKeyMode(NProtobufJson::TProto2JsonConfig::MissingKeyDefault)
        .AddStringTransform(MakeIntrusive<NProtobufJson::TBase64EncodeBytesTransform>());

} // namespace

TEventProtobufMessageFieldPrinter::TEventProtobufMessageFieldPrinter(EProtobufMessageFieldPrintMode mode)
    : Mode(mode)
{}

template <>
void TEventProtobufMessageFieldPrinter::PrintProtobufMessageFieldToOutput<google::protobuf::Message, false>(const google::protobuf::Message& field, TEventFieldOutput& output) {
    switch (Mode) {
        case EProtobufMessageFieldPrintMode::DEFAULT:
        case EProtobufMessageFieldPrintMode::JSON: {
            // Do not use field.PrintJSON() here: IGNIETFERRO-2002
            NProtobufJson::Proto2Json(field, output, PROTO_2_JSON_CONFIG);
            break;
        }
    }
}