aboutsummaryrefslogtreecommitdiffstats
path: root/library/cpp/eventlog/event_field_printer.h
blob: 835e8f4a850c254c58d7780400ba4b325a726e7f (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
28
29
30
31
32
33
34
35
36
37
38
#pragma once

#include "event_field_output.h"

#include <google/protobuf/message.h>

// NB: For historical reasons print code for all primitive types/repeated fields/etc generated by https://a.yandex-team.ru/arc/trunk/arcadia/tools/event2cpp

enum class EProtobufMessageFieldPrintMode {
    // Use <TEventProtobufMessageFieldType>::Print method for fields that has it
    // Print json for other fields
    DEFAULT = 0,

    JSON = 1,
};

class TEventProtobufMessageFieldPrinter {
public:
    explicit TEventProtobufMessageFieldPrinter(EProtobufMessageFieldPrintMode mode);

    template <typename TEventProtobufMessageFieldType, bool HasPrintFunction>
    void PrintProtobufMessageFieldToOutput(const TEventProtobufMessageFieldType& field, TEventFieldOutput& output) {
        if constexpr (HasPrintFunction) {
            if (Mode == EProtobufMessageFieldPrintMode::DEFAULT) {
                field.Print(output.GetOutputStream(), output.GetFlags());
                return;
            }
        }

        PrintProtobufMessageFieldToOutput<google::protobuf::Message, false>(field, output);
    }

    template <>
    void PrintProtobufMessageFieldToOutput<google::protobuf::Message, false>(const google::protobuf::Message& field, TEventFieldOutput& output);

private:
    EProtobufMessageFieldPrintMode Mode;
};