aboutsummaryrefslogtreecommitdiffstats
path: root/library/cpp/monlib/deprecated/json/writer.cpp
blob: fca3834ebc311eb0a70322504a13d2b93038f030 (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
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
#include "writer.h" 

namespace NMonitoring { 
    TDeprecatedJsonWriter::TDeprecatedJsonWriter(IOutputStream* out) 
        : JsonWriter(out, false) 
        , State(STATE_ROOT) 
    { 
    } 

    void TDeprecatedJsonWriter::TransitionState(EState current, EState next) { 
        if (State != current) { 
            ythrow yexception() << "wrong state"; 
        } 
        State = next; 
    } 

    void TDeprecatedJsonWriter::OpenDocument() { 
        TransitionState(STATE_ROOT, STATE_DOCUMENT); 
        JsonWriter.OpenMap(); 
    }

    void TDeprecatedJsonWriter::CloseDocument() { 
        TransitionState(STATE_DOCUMENT, STATE_ROOT); 
        JsonWriter.CloseMap(); 
        JsonWriter.Flush(); 
    } 

    void TDeprecatedJsonWriter::OpenCommonLabels() { 
        TransitionState(STATE_DOCUMENT, STATE_COMMON_LABELS); 
        JsonWriter.Write("commonLabels"); 
        JsonWriter.OpenMap(); 
    } 

    void TDeprecatedJsonWriter::CloseCommonLabels() { 
        TransitionState(STATE_COMMON_LABELS, STATE_DOCUMENT); 
        JsonWriter.CloseMap(); 
    } 

    void TDeprecatedJsonWriter::WriteCommonLabel(TStringBuf name, TStringBuf value) { 
        TransitionState(STATE_COMMON_LABELS, STATE_COMMON_LABELS); 
        JsonWriter.Write(name, value); 
    } 

    void TDeprecatedJsonWriter::OpenMetrics() { 
        TransitionState(STATE_DOCUMENT, STATE_METRICS); 
        JsonWriter.Write("sensors"); 
        JsonWriter.OpenArray(); 
    } 

    void TDeprecatedJsonWriter::CloseMetrics() { 
        TransitionState(STATE_METRICS, STATE_DOCUMENT); 
        JsonWriter.CloseArray(); 
    } 

    void TDeprecatedJsonWriter::OpenMetric() { 
        TransitionState(STATE_METRICS, STATE_METRIC); 
        JsonWriter.OpenMap(); 
    } 

    void TDeprecatedJsonWriter::CloseMetric() { 
        TransitionState(STATE_METRIC, STATE_METRICS); 
        JsonWriter.CloseMap(); 
    } 

    void TDeprecatedJsonWriter::OpenLabels() { 
        TransitionState(STATE_METRIC, STATE_LABELS); 
        JsonWriter.Write("labels"); 
        JsonWriter.OpenMap(); 
    } 

    void TDeprecatedJsonWriter::CloseLabels() { 
        TransitionState(STATE_LABELS, STATE_METRIC); 
        JsonWriter.CloseMap(); 
    } 

    void TDeprecatedJsonWriter::WriteLabel(TStringBuf name, TStringBuf value) { 
        TransitionState(STATE_LABELS, STATE_LABELS); 
        JsonWriter.Write(name, value); 
    } 

    void TDeprecatedJsonWriter::WriteModeDeriv() { 
        TransitionState(STATE_METRIC, STATE_METRIC); 
        JsonWriter.Write("mode", "deriv"); 
    } 

    void TDeprecatedJsonWriter::WriteValue(long long value) { 
        TransitionState(STATE_METRIC, STATE_METRIC); 
        JsonWriter.Write("value", value); 
    } 

    void TDeprecatedJsonWriter::WriteDoubleValue(double value) { 
        TransitionState(STATE_METRIC, STATE_METRIC); 
        JsonWriter.Write("value", value); 
    } 

    void TDeprecatedJsonWriter::WriteTs(ui64 ts) { 
        TransitionState(STATE_METRIC, STATE_METRIC); 
        JsonWriter.Write("ts", ts); 
    } 
}