aboutsummaryrefslogtreecommitdiffstats
path: root/library/cpp/yt/yson/consumer.h
blob: ce295ad6088c025644c110ea1a3ee610716e538e (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
101
102
103
104
105
106
107
108
109
110
111
#pragma once 
 
#include <util/generic/strbuf.h> 

#include <util/system/defaults.h> 
 
#include <library/cpp/yt/yson_string/public.h> 
 
namespace NYT::NYson { 

//////////////////////////////////////////////////////////////////////////////// 
 
//! A SAX-like interface for parsing a YSON stream. 
struct IYsonConsumer
{
    virtual ~IYsonConsumer() = default;
 
    //! The current item is a string scalar (IStringNode). 
    /*! 
     *  \param value A scalar value. 
     */ 
    virtual void OnStringScalar(TStringBuf value) = 0; 
 
    //! The current item is an integer scalar (IInt64Node). 
    /*! 
     *  \param value A scalar value. 
     */ 
    virtual void OnInt64Scalar(i64 value) = 0; 
 
    //! The current item is an integer scalar (IUint64Node). 
    /*! 
     *  \param value A scalar value. 
     */ 
    virtual void OnUint64Scalar(ui64 scalar) = 0; 
 
    //! The current item is an FP scalar (IDoubleNode). 
    /*! 
     *  \param value A scalar value. 
     */ 
    virtual void OnDoubleScalar(double value) = 0; 
 
    //! The current item is an boolean scalar (IBooleanNode). 
    /*! 
     *  \param value A scalar value. 
     */ 
    virtual void OnBooleanScalar(bool value) = 0; 
 
    //! The current item is an entity (IEntityNode). 
    virtual void OnEntity() = 0; 
 
    //! Starts a list (IListNode). 
    /*! 
     *  The events describing a list are raised as follows: 
     *  - #OnBeginList 
     *  - For each item: #OnListItem followed by the description of the item 
     *  - #OnEndList 
     */ 
    virtual void OnBeginList() = 0; 
 
    //! Designates a list item. 
    virtual void OnListItem() = 0; 
 
    //! Ends the current list. 
    virtual void OnEndList() = 0; 
 
    //! Starts a map (IMapNode). 
    /*! 
     *  The events describing a map are raised as follows: 
     *  - #OnBeginMap 
     *  - For each item: #OnKeyedItem followed by the description of the item 
     *  - #OnEndMap 
     */ 
    virtual void OnBeginMap() = 0; 
 
    //! Designates a keyed item (in map or in attributes). 
    /*! 
     *  \param key Item key in the map. 
     */ 
    virtual void OnKeyedItem(TStringBuf key) = 0; 
 
    //! Ends the current map. 
    virtual void OnEndMap() = 0; 
 
    //! Starts attributes. 
    /*! 
     *  An arbitrary node may be preceeded by attributes. 
     * 
     *  The events describing attributes are raised as follows: 
     *  - #OnBeginAttributes 
     *  - For each item: #OnKeyedItem followed by the description of the item 
     *  - #OnEndAttributes 
     */ 
    virtual void OnBeginAttributes() = 0; 
 
    //! Ends the current attribute list. 
    virtual void OnEndAttributes() = 0; 
 
    //! Inserts YSON-serialized node or fragment. 
    /*! 
     *  \param yson Serialized data. 
     *  \param type Type of data. 
     */ 
    virtual void OnRaw(TStringBuf yson, EYsonType type) = 0; 
 
    // Extension methods. 
    void OnRaw(const TYsonStringBuf& yson); 
}; 
 
//////////////////////////////////////////////////////////////////////////////// 
 
} // namespace NYT::NYson