aboutsummaryrefslogtreecommitdiffstats
path: root/library/cpp/protobuf/json/json_output.h
blob: df143af57a7e5bf4112f8b563014d27cbe16f3a4 (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
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
#pragma once

#include <util/generic/ptr.h>
#include <util/generic/strbuf.h>

namespace NProtobufJson {
    class IJsonOutput {
    public:
        template <typename T>
        IJsonOutput& Write(const T& t) {
            DoWrite(t);
            return *this;
        }
        IJsonOutput& WriteNull() {
            DoWriteNull();
            return *this;
        }

        IJsonOutput& BeginList() {
            DoBeginList();
            return *this;
        }
        IJsonOutput& EndList() {
            DoEndList();
            return *this;
        }

        IJsonOutput& BeginObject() {
            DoBeginObject();
            return *this;
        }
        IJsonOutput& WriteKey(const TStringBuf& key) {
            DoWriteKey(key);
            return *this;
        }
        IJsonOutput& EndObject() {
            DoEndObject();
            return *this;
        }

        IJsonOutput& WriteRawJson(const TStringBuf& str) {
            DoWriteRawJson(str);
            return *this;
        }

        virtual ~IJsonOutput() {
        }

    protected:
        virtual void DoWrite(const TStringBuf& s) = 0;
        virtual void DoWrite(const TString& s) = 0;
        virtual void DoWrite(int i) = 0;
        void DoWrite(long i) {
            DoWrite(static_cast<long long>(i));
        }
        virtual void DoWrite(long long i) = 0;
        virtual void DoWrite(unsigned int i) = 0;
        void DoWrite(unsigned long i) {
            DoWrite(static_cast<unsigned long long>(i));
        }
        virtual void DoWrite(unsigned long long i) = 0;
        virtual void DoWrite(float f) = 0;
        virtual void DoWrite(double f) = 0;
        virtual void DoWrite(bool b) = 0;
        virtual void DoWriteNull() = 0;

        virtual void DoBeginList() = 0;
        virtual void DoEndList() = 0;

        virtual void DoBeginObject() = 0;
        virtual void DoWriteKey(const TStringBuf& key) = 0;
        virtual void DoEndObject() = 0;

        virtual void DoWriteRawJson(const TStringBuf& str) = 0;
    };

    using TJsonMapOutputPtr = THolder<IJsonOutput>;

}