/proc/self/cwd/source/extensions/filters/network/thrift_proxy/decoder_events.h
Line | Count | Source (jump to first uncovered line) |
1 | | #pragma once |
2 | | |
3 | | #include "source/extensions/filters/network/thrift_proxy/metadata.h" |
4 | | #include "source/extensions/filters/network/thrift_proxy/thrift.h" |
5 | | |
6 | | namespace Envoy { |
7 | | namespace Extensions { |
8 | | namespace NetworkFilters { |
9 | | namespace ThriftProxy { |
10 | | |
11 | | enum class FilterStatus { |
12 | | // Continue filter chain iteration. |
13 | | Continue, |
14 | | |
15 | | // Stop iterating over filters in the filter chain. Iteration must be explicitly restarted via |
16 | | // continueDecoding(). |
17 | | StopIteration |
18 | | }; |
19 | | |
20 | | enum class DecoderEvent { |
21 | | TransportBegin, |
22 | | TransportEnd, |
23 | | PassthroughData, |
24 | | MessageBegin, |
25 | | MessageEnd, |
26 | | StructBegin, |
27 | | StructEnd, |
28 | | FieldBegin, |
29 | | FieldEnd, |
30 | | BoolValue, |
31 | | ByteValue, |
32 | | DoubleValue, |
33 | | Int16Value, |
34 | | Int32Value, |
35 | | Int64Value, |
36 | | StringValue, |
37 | | ListBegin, |
38 | | ListEnd, |
39 | | SetBegin, |
40 | | SetEnd, |
41 | | MapBegin, |
42 | | MapEnd, |
43 | | ContinueDecode |
44 | | }; |
45 | | |
46 | | class DecoderEventHandler { |
47 | | public: |
48 | 0 | virtual ~DecoderEventHandler() = default; |
49 | | |
50 | | /** |
51 | | * Indicates the start of a Thrift transport frame was detected. Unframed transports generate |
52 | | * simulated start messages. |
53 | | * @param metadata MessageMetadataSharedPtr describing as much as is currently known about the |
54 | | * message |
55 | | */ |
56 | | virtual FilterStatus transportBegin(MessageMetadataSharedPtr metadata) PURE; |
57 | | |
58 | | /** |
59 | | * Indicates the end of a Thrift transport frame was detected. Unframed transport generate |
60 | | * simulated complete messages. |
61 | | */ |
62 | | virtual FilterStatus transportEnd() PURE; |
63 | | |
64 | | /** |
65 | | * Indicates raw bytes after metadata in a Thrift transport frame was detected. |
66 | | * Filters should not modify data except for the router. |
67 | | * @param data data to send as passthrough |
68 | | * @return FilterStatus to indicate if filter chain iteration should continue |
69 | | */ |
70 | | virtual FilterStatus passthroughData(Buffer::Instance& data) PURE; |
71 | | |
72 | | /** |
73 | | * Indicates that the start of a Thrift protocol message was detected. |
74 | | * @param metadata MessageMetadataSharedPtr describing the message |
75 | | * @return FilterStatus to indicate if filter chain iteration should continue |
76 | | */ |
77 | | virtual FilterStatus messageBegin(MessageMetadataSharedPtr metadata) PURE; |
78 | | |
79 | | /** |
80 | | * Indicates that the end of a Thrift protocol message was detected. |
81 | | * @return FilterStatus to indicate if filter chain iteration should continue |
82 | | */ |
83 | | virtual FilterStatus messageEnd() PURE; |
84 | | |
85 | | /** |
86 | | * Indicates that the start of a Thrift protocol struct was detected. |
87 | | * @param name the name of the struct, if available |
88 | | * @return FilterStatus to indicate if filter chain iteration should continue |
89 | | */ |
90 | | virtual FilterStatus structBegin(absl::string_view name) PURE; |
91 | | |
92 | | /** |
93 | | * Indicates that the end of a Thrift protocol struct was detected. |
94 | | * @return FilterStatus to indicate if filter chain iteration should continue |
95 | | */ |
96 | | virtual FilterStatus structEnd() PURE; |
97 | | |
98 | | /** |
99 | | * Indicates that the start of Thrift protocol struct field was detected. |
100 | | * @param name the name of the field, if available |
101 | | * @param field_type the type of the field |
102 | | * @param field_id the field id |
103 | | * @return FilterStatus to indicate if filter chain iteration should continue |
104 | | */ |
105 | | virtual FilterStatus fieldBegin(absl::string_view name, FieldType& field_type, |
106 | | int16_t& field_id) PURE; |
107 | | |
108 | | /** |
109 | | * Indicates that the end of a Thrift protocol struct field was detected. |
110 | | * @return FilterStatus to indicate if filter chain iteration should continue |
111 | | */ |
112 | | virtual FilterStatus fieldEnd() PURE; |
113 | | |
114 | | /** |
115 | | * A struct field, map key, map value, list element or set element was detected. |
116 | | * @param value type value of the field |
117 | | * @return FilterStatus to indicate if filter chain iteration should continue |
118 | | */ |
119 | | virtual FilterStatus boolValue(bool& value) PURE; |
120 | | virtual FilterStatus byteValue(uint8_t& value) PURE; |
121 | | virtual FilterStatus int16Value(int16_t& value) PURE; |
122 | | virtual FilterStatus int32Value(int32_t& value) PURE; |
123 | | virtual FilterStatus int64Value(int64_t& value) PURE; |
124 | | virtual FilterStatus doubleValue(double& value) PURE; |
125 | | virtual FilterStatus stringValue(absl::string_view value) PURE; |
126 | | |
127 | | /** |
128 | | * Indicates the start of a Thrift protocol map was detected. |
129 | | * @param key_type the map key type |
130 | | * @param value_type the map value type |
131 | | * @param size the number of key-value pairs |
132 | | * @return FilterStatus to indicate if filter chain iteration should continue |
133 | | */ |
134 | | virtual FilterStatus mapBegin(FieldType& key_type, FieldType& value_type, uint32_t& size) PURE; |
135 | | |
136 | | /** |
137 | | * Indicates that the end of a Thrift protocol map was detected. |
138 | | * @return FilterStatus to indicate if filter chain iteration should continue |
139 | | */ |
140 | | virtual FilterStatus mapEnd() PURE; |
141 | | |
142 | | /** |
143 | | * Indicates the start of a Thrift protocol list was detected. |
144 | | * @param elem_type the list value type |
145 | | * @param size the number of values in the list |
146 | | * @return FilterStatus to indicate if filter chain iteration should continue |
147 | | */ |
148 | | virtual FilterStatus listBegin(FieldType& elem_type, uint32_t& size) PURE; |
149 | | |
150 | | /** |
151 | | * Indicates that the end of a Thrift protocol list was detected. |
152 | | * @return FilterStatus to indicate if filter chain iteration should continue |
153 | | */ |
154 | | virtual FilterStatus listEnd() PURE; |
155 | | |
156 | | /** |
157 | | * Indicates the start of a Thrift protocol set was detected. |
158 | | * @param elem_type the set value type |
159 | | * @param size the number of values in the set |
160 | | * @return FilterStatus to indicate if filter chain iteration should continue |
161 | | */ |
162 | | virtual FilterStatus setBegin(FieldType& elem_type, uint32_t& size) PURE; |
163 | | |
164 | | /** |
165 | | * Indicates that the end of a Thrift protocol set was detected. |
166 | | * @return FilterStatus to indicate if filter chain iteration should continue |
167 | | */ |
168 | | virtual FilterStatus setEnd() PURE; |
169 | | }; |
170 | | |
171 | | using DecoderEventHandlerSharedPtr = std::shared_ptr<DecoderEventHandler>; |
172 | | |
173 | | } // namespace ThriftProxy |
174 | | } // namespace NetworkFilters |
175 | | } // namespace Extensions |
176 | | } // namespace Envoy |