]>
Commit | Line | Data |
---|---|---|
f67539c2 TL |
1 | /* |
2 | * Licensed to the Apache Software Foundation (ASF) under one | |
3 | * or more contributor license agreements. See the NOTICE file | |
4 | * distributed with this work for additional information | |
5 | * regarding copyright ownership. The ASF licenses this file | |
6 | * to you under the Apache License, Version 2.0 (the | |
7 | * "License"); you may not use this file except in compliance | |
8 | * with the License. You may obtain a copy of the License at | |
9 | * | |
10 | * http://www.apache.org/licenses/LICENSE-2.0 | |
11 | * | |
12 | * Unless required by applicable law or agreed to in writing, | |
13 | * software distributed under the License is distributed on an | |
14 | * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY | |
15 | * KIND, either express or implied. See the License for the | |
16 | * specific language governing permissions and limitations | |
17 | * under the License. | |
18 | */ | |
19 | ||
20 | #ifndef _THRIFT_PROTOCOL_H | |
21 | #define _THRIFT_PROTOCOL_H | |
22 | ||
23 | #include <glib-object.h> | |
24 | ||
25 | #include <thrift/c_glib/transport/thrift_transport.h> | |
26 | ||
27 | G_BEGIN_DECLS | |
28 | ||
29 | /*! \file thrift_protocol.h | |
30 | * \brief Abstract class for Thrift protocol implementations. | |
31 | */ | |
32 | ||
33 | /** | |
34 | * Enumerated definition of the types that the Thrift protocol supports. | |
35 | * Take special note of the T_END type which is used specifically to mark | |
36 | * the end of a sequence of fields. | |
37 | */ | |
38 | typedef enum { | |
39 | T_STOP = 0, | |
40 | T_VOID = 1, | |
41 | T_BOOL = 2, | |
42 | T_BYTE = 3, | |
43 | T_I08 = 3, | |
44 | T_I16 = 6, | |
45 | T_I32 = 8, | |
46 | T_U64 = 9, | |
47 | T_I64 = 10, | |
48 | T_DOUBLE = 4, | |
49 | T_STRING = 11, | |
50 | T_UTF7 = 11, | |
51 | T_STRUCT = 12, | |
52 | T_MAP = 13, | |
53 | T_SET = 14, | |
54 | T_LIST = 15, | |
55 | T_UTF8 = 16, | |
56 | T_UTF16 = 17 | |
57 | } ThriftType; | |
58 | ||
59 | /** | |
60 | * Enumerated definition of the message types that the Thrift protocol | |
61 | * supports. | |
62 | */ | |
63 | typedef enum { | |
64 | T_CALL = 1, | |
65 | T_REPLY = 2, | |
66 | T_EXCEPTION = 3, | |
67 | T_ONEWAY = 4 | |
68 | } ThriftMessageType; | |
69 | ||
70 | /* type macros */ | |
71 | #define THRIFT_TYPE_PROTOCOL (thrift_protocol_get_type ()) | |
72 | #define THRIFT_PROTOCOL(obj) (G_TYPE_CHECK_INSTANCE_CAST ((obj), THRIFT_TYPE_PROTOCOL, ThriftProtocol)) | |
73 | #define THRIFT_IS_PROTOCOL(obj) (G_TYPE_CHECK_INSTANCE_TYPE ((obj), THRIFT_TYPE_PROTOCOL)) | |
74 | #define THRIFT_PROTOCOL_CLASS(c) (G_TYPE_CHECK_CLASS_CAST ((c), THRIFT_TYPE_PROTOCOL, ThriftProtocolClass)) | |
75 | #define THRIFT_IS_PROTOCOL_CLASS(c) (G_TYPE_CHECK_CLASS_TYPE ((c), THRIFT_TYPE_PROTOCOL)) | |
76 | #define THRIFT_PROTOCOL_GET_CLASS(obj) (G_TYPE_INSTANCE_GET_CLASS ((obj), THRIFT_TYPE_PROTOCOL, ThriftProtocolClass)) | |
77 | ||
78 | typedef struct _ThriftProtocol ThriftProtocol; | |
79 | ||
80 | /*! | |
81 | * Thrift Protocol object | |
82 | */ | |
83 | struct _ThriftProtocol | |
84 | { | |
85 | GObject parent; | |
86 | ||
87 | /* protected */ | |
88 | ThriftTransport *transport; | |
89 | }; | |
90 | ||
91 | typedef struct _ThriftProtocolClass ThriftProtocolClass; | |
92 | ||
93 | /*! | |
94 | * Thrift Protocol class | |
95 | */ | |
96 | struct _ThriftProtocolClass | |
97 | { | |
98 | GObjectClass parent; | |
99 | ||
100 | gint32 (*write_message_begin) (ThriftProtocol *protocol, const gchar *name, | |
101 | const ThriftMessageType message_type, | |
102 | const gint32 seqid, GError **error); | |
103 | gint32 (*write_message_end) (ThriftProtocol *protocol, GError **error); | |
104 | gint32 (*write_struct_begin) (ThriftProtocol *protocol, const gchar *name, | |
105 | GError **error); | |
106 | gint32 (*write_struct_end) (ThriftProtocol *protocol, GError **error); | |
107 | gint32 (*write_field_begin) (ThriftProtocol *protocol, const gchar *name, | |
108 | const ThriftType field_type, | |
109 | const gint16 field_id, GError **error); | |
110 | gint32 (*write_field_end) (ThriftProtocol *protocol, GError **error); | |
111 | gint32 (*write_field_stop) (ThriftProtocol *protocol, GError **error); | |
112 | gint32 (*write_map_begin) (ThriftProtocol *protocol, | |
113 | const ThriftType key_type, | |
114 | const ThriftType value_type, | |
115 | const guint32 size, GError **error); | |
116 | gint32 (*write_map_end) (ThriftProtocol *protocol, GError **error); | |
117 | gint32 (*write_list_begin) (ThriftProtocol *protocol, | |
118 | const ThriftType element_type, | |
119 | const guint32 size, GError **error); | |
120 | gint32 (*write_list_end) (ThriftProtocol *protocol, GError **error); | |
121 | gint32 (*write_set_begin) (ThriftProtocol *protocol, | |
122 | const ThriftType element_type, | |
123 | const guint32 size, GError **error); | |
124 | gint32 (*write_set_end) (ThriftProtocol *protocol, GError **error); | |
125 | gint32 (*write_bool) (ThriftProtocol *protocol, const gboolean value, | |
126 | GError **error); | |
127 | gint32 (*write_byte) (ThriftProtocol *protocol, const gint8 value, | |
128 | GError **error); | |
129 | gint32 (*write_i16) (ThriftProtocol *protocol, const gint16 value, | |
130 | GError **error); | |
131 | gint32 (*write_i32) (ThriftProtocol *protocol, const gint32 value, | |
132 | GError **error); | |
133 | gint32 (*write_i64) (ThriftProtocol *protocol, const gint64 value, | |
134 | GError **error); | |
135 | gint32 (*write_double) (ThriftProtocol *protocol, const gdouble value, | |
136 | GError **error); | |
137 | gint32 (*write_string) (ThriftProtocol *protocol, const gchar *str, | |
138 | GError **error); | |
139 | gint32 (*write_binary) (ThriftProtocol *protocol, const gpointer buf, | |
140 | const guint32 len, GError **error); | |
141 | ||
142 | gint32 (*read_message_begin) (ThriftProtocol *thrift_protocol, gchar **name, | |
143 | ThriftMessageType *message_type, | |
144 | gint32 *seqid, GError **error); | |
145 | gint32 (*read_message_end) (ThriftProtocol *protocol, GError **error); | |
146 | gint32 (*read_struct_begin) (ThriftProtocol *protocol, gchar **name, | |
147 | GError **error); | |
148 | gint32 (*read_struct_end) (ThriftProtocol *protocol, GError **error); | |
149 | gint32 (*read_field_begin) (ThriftProtocol *protocol, gchar **name, | |
150 | ThriftType *field_type, gint16 *field_id, | |
151 | GError **error); | |
152 | gint32 (*read_field_end) (ThriftProtocol *protocol, GError **error); | |
153 | gint32 (*read_map_begin) (ThriftProtocol *protocol, ThriftType *key_type, | |
154 | ThriftType *value_type, guint32 *size, | |
155 | GError **error); | |
156 | gint32 (*read_map_end) (ThriftProtocol *protocol, GError **error); | |
157 | gint32 (*read_list_begin) (ThriftProtocol *protocol, ThriftType *element_type, | |
158 | guint32 *size, GError **error); | |
159 | gint32 (*read_list_end) (ThriftProtocol *protocol, GError **error); | |
160 | gint32 (*read_set_begin) (ThriftProtocol *protocol, ThriftType *element_type, | |
161 | guint32 *size, GError **error); | |
162 | gint32 (*read_set_end) (ThriftProtocol *protocol, GError **error); | |
163 | gint32 (*read_bool) (ThriftProtocol *protocol, gboolean *value, | |
164 | GError **error); | |
165 | gint32 (*read_byte) (ThriftProtocol *protocol, gint8 *value, GError **error); | |
166 | gint32 (*read_i16) (ThriftProtocol *protocol, gint16 *value, GError **error); | |
167 | gint32 (*read_i32) (ThriftProtocol *protocol, gint32 *value, GError **error); | |
168 | gint32 (*read_i64) (ThriftProtocol *protocol, gint64 *value, GError **error); | |
169 | gint32 (*read_double) (ThriftProtocol *protocol, gdouble *value, | |
170 | GError **error); | |
171 | gint32 (*read_string) (ThriftProtocol *protocol, gchar **str, GError **error); | |
172 | gint32 (*read_binary) (ThriftProtocol *protocol, gpointer *buf, | |
173 | guint32 *len, GError **error); | |
174 | }; | |
175 | ||
176 | /* used by THRIFT_TYPE_PROTOCOL */ | |
177 | GType thrift_protocol_get_type (void); | |
178 | ||
179 | /* virtual public methods */ | |
180 | gint32 thrift_protocol_write_message_begin (ThriftProtocol *protocol, | |
181 | const gchar *name, const ThriftMessageType message_type, | |
182 | const gint32 seqid, GError **error); | |
183 | ||
184 | gint32 thrift_protocol_write_message_end (ThriftProtocol *protocol, | |
185 | GError **error); | |
186 | ||
187 | gint32 thrift_protocol_write_struct_begin (ThriftProtocol *protocol, | |
188 | const gchar *name, | |
189 | GError **error); | |
190 | ||
191 | gint32 thrift_protocol_write_struct_end (ThriftProtocol *protocol, | |
192 | GError **error); | |
193 | ||
194 | gint32 thrift_protocol_write_field_begin (ThriftProtocol *protocol, | |
195 | const gchar *name, | |
196 | const ThriftType field_type, | |
197 | const gint16 field_id, | |
198 | GError **error); | |
199 | ||
200 | gint32 thrift_protocol_write_field_end (ThriftProtocol *protocol, | |
201 | GError **error); | |
202 | ||
203 | gint32 thrift_protocol_write_field_stop (ThriftProtocol *protocol, | |
204 | GError **error); | |
205 | ||
206 | gint32 thrift_protocol_write_map_begin (ThriftProtocol *protocol, | |
207 | const ThriftType key_type, | |
208 | const ThriftType value_type, | |
209 | const guint32 size, GError **error); | |
210 | ||
211 | gint32 thrift_protocol_write_map_end (ThriftProtocol *protocol, GError **error); | |
212 | ||
213 | gint32 thrift_protocol_write_list_begin (ThriftProtocol *protocol, | |
214 | const ThriftType element_type, | |
215 | const guint32 size, GError **error); | |
216 | ||
217 | gint32 thrift_protocol_write_list_end (ThriftProtocol *protocol, | |
218 | GError **error); | |
219 | ||
220 | gint32 thrift_protocol_write_set_begin (ThriftProtocol *protocol, | |
221 | const ThriftType element_type, | |
222 | const guint32 size, GError **error); | |
223 | ||
224 | gint32 thrift_protocol_write_set_end (ThriftProtocol *protocol, | |
225 | GError **error); | |
226 | ||
227 | gint32 thrift_protocol_write_bool (ThriftProtocol *protocol, | |
228 | const gboolean value, GError **error); | |
229 | ||
230 | gint32 thrift_protocol_write_byte (ThriftProtocol *protocol, const gint8 value, | |
231 | GError **error); | |
232 | ||
233 | gint32 thrift_protocol_write_i16 (ThriftProtocol *protocol, const gint16 value, | |
234 | GError **error); | |
235 | ||
236 | gint32 thrift_protocol_write_i32 (ThriftProtocol *protocol, const gint32 value, | |
237 | GError **error); | |
238 | ||
239 | gint32 thrift_protocol_write_i64 (ThriftProtocol *protocol, const gint64 value, | |
240 | GError **error); | |
241 | ||
242 | gint32 thrift_protocol_write_double (ThriftProtocol *protocol, | |
243 | const gdouble value, GError **error); | |
244 | ||
245 | gint32 thrift_protocol_write_string (ThriftProtocol *protocol, | |
246 | const gchar *str, GError **error); | |
247 | ||
248 | gint32 thrift_protocol_write_binary (ThriftProtocol *protocol, | |
249 | const gpointer buf, | |
250 | const guint32 len, GError **error); | |
251 | ||
252 | gint32 thrift_protocol_read_message_begin (ThriftProtocol *thrift_protocol, | |
253 | gchar **name, | |
254 | ThriftMessageType *message_type, | |
255 | gint32 *seqid, GError **error); | |
256 | ||
257 | gint32 thrift_protocol_read_message_end (ThriftProtocol *protocol, | |
258 | GError **error); | |
259 | ||
260 | gint32 thrift_protocol_read_struct_begin (ThriftProtocol *protocol, | |
261 | gchar **name, | |
262 | GError **error); | |
263 | ||
264 | gint32 thrift_protocol_read_struct_end (ThriftProtocol *protocol, | |
265 | GError **error); | |
266 | ||
267 | gint32 thrift_protocol_read_field_begin (ThriftProtocol *protocol, | |
268 | gchar **name, | |
269 | ThriftType *field_type, | |
270 | gint16 *field_id, | |
271 | GError **error); | |
272 | ||
273 | gint32 thrift_protocol_read_field_end (ThriftProtocol *protocol, | |
274 | GError **error); | |
275 | ||
276 | gint32 thrift_protocol_read_map_begin (ThriftProtocol *protocol, | |
277 | ThriftType *key_type, | |
278 | ThriftType *value_type, guint32 *size, | |
279 | GError **error); | |
280 | ||
281 | gint32 thrift_protocol_read_map_end (ThriftProtocol *protocol, GError **error); | |
282 | ||
283 | gint32 thrift_protocol_read_list_begin (ThriftProtocol *protocol, | |
284 | ThriftType *element_type, | |
285 | guint32 *size, GError **error); | |
286 | ||
287 | gint32 thrift_protocol_read_list_end (ThriftProtocol *protocol, GError **error); | |
288 | ||
289 | gint32 thrift_protocol_read_set_begin (ThriftProtocol *protocol, | |
290 | ThriftType *element_type, | |
291 | guint32 *size, GError **error); | |
292 | ||
293 | gint32 thrift_protocol_read_set_end (ThriftProtocol *protocol, GError **error); | |
294 | ||
295 | gint32 thrift_protocol_read_bool (ThriftProtocol *protocol, gboolean *value, | |
296 | GError **error); | |
297 | ||
298 | gint32 thrift_protocol_read_byte (ThriftProtocol *protocol, gint8 *value, | |
299 | GError **error); | |
300 | ||
301 | gint32 thrift_protocol_read_i16 (ThriftProtocol *protocol, gint16 *value, | |
302 | GError **error); | |
303 | ||
304 | gint32 thrift_protocol_read_i32 (ThriftProtocol *protocol, gint32 *value, | |
305 | GError **error); | |
306 | ||
307 | gint32 thrift_protocol_read_i64 (ThriftProtocol *protocol, gint64 *value, | |
308 | GError **error); | |
309 | ||
310 | gint32 thrift_protocol_read_double (ThriftProtocol *protocol, | |
311 | gdouble *value, GError **error); | |
312 | ||
313 | gint32 thrift_protocol_read_string (ThriftProtocol *protocol, | |
314 | gchar **str, GError **error); | |
315 | ||
316 | gint32 thrift_protocol_read_binary (ThriftProtocol *protocol, | |
317 | gpointer *buf, guint32 *len, | |
318 | GError **error); | |
319 | ||
320 | gint32 thrift_protocol_skip (ThriftProtocol *protocol, ThriftType type, | |
321 | GError **error); | |
322 | ||
323 | /* define error types */ | |
324 | typedef enum | |
325 | { | |
326 | THRIFT_PROTOCOL_ERROR_UNKNOWN, | |
327 | THRIFT_PROTOCOL_ERROR_INVALID_DATA, | |
328 | THRIFT_PROTOCOL_ERROR_NEGATIVE_SIZE, | |
329 | THRIFT_PROTOCOL_ERROR_SIZE_LIMIT, | |
330 | THRIFT_PROTOCOL_ERROR_BAD_VERSION, | |
331 | THRIFT_PROTOCOL_ERROR_NOT_IMPLEMENTED, | |
332 | THRIFT_PROTOCOL_ERROR_DEPTH_LIMIT | |
333 | } ThriftProtocolError; | |
334 | ||
335 | /* define an error domain for GError to use */ | |
336 | GQuark thrift_protocol_error_quark (void); | |
337 | #define THRIFT_PROTOCOL_ERROR (thrift_protocol_error_quark ()) | |
338 | ||
339 | G_END_DECLS | |
340 | ||
341 | #endif /* _THRIFT_PROTOCOL_H */ |