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
10 * http://www.apache.org/licenses/LICENSE-2.0
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
23 #include <glib-object.h>
25 #include <thrift/c_glib/thrift.h>
26 #include <thrift/c_glib/protocol/thrift_protocol.h>
27 #include <thrift/c_glib/protocol/thrift_binary_protocol.h>
28 #include <thrift/c_glib/protocol/thrift_protocol_decorator.h>
30 G_DEFINE_TYPE(ThriftProtocolDecorator
, thrift_protocol_decorator
, THRIFT_TYPE_PROTOCOL
)
35 PROP_THRIFT_TYPE_PROTOCOL_DECORATOR_CONCRETE_PROTOCOL
= 1,
36 PROP_THRIFT_TYPE_PROTOCOL_DECORATOR_END
39 static GParamSpec
*thrift_protocol_decorator_obj_properties
[PROP_THRIFT_TYPE_PROTOCOL_DECORATOR_END
] = { NULL
, };
46 thrift_protocol_decorator_write_message_begin (ThriftProtocol
*protocol
,
48 const ThriftMessageType message_type
,
49 const gint32 seqid
, GError
**error
)
52 ThriftProtocolDecorator
*self
= THRIFT_PROTOCOL_DECORATOR (protocol
);
53 ThriftProtocolClass
*proto
= THRIFT_PROTOCOL_GET_CLASS (self
->concrete_protocol
);
55 g_debug("Concrete protocol %p | %p", (void *)self
->concrete_protocol
, (void *)proto
);
57 return proto
->write_message_begin (self
->concrete_protocol
, name
,
63 thrift_protocol_decorator_write_message_end (ThriftProtocol
*protocol
, GError
**error
)
65 ThriftProtocolDecorator
*self
= THRIFT_PROTOCOL_DECORATOR (protocol
);
67 return THRIFT_PROTOCOL_GET_CLASS (self
->concrete_protocol
)->write_message_end (self
->concrete_protocol
,
72 thrift_protocol_decorator_write_struct_begin (ThriftProtocol
*protocol
, const gchar
*name
,
75 ThriftProtocolDecorator
*self
= THRIFT_PROTOCOL_DECORATOR (protocol
);
77 return THRIFT_PROTOCOL_GET_CLASS (self
->concrete_protocol
)->write_struct_begin (self
->concrete_protocol
,
82 thrift_protocol_decorator_write_struct_end (ThriftProtocol
*protocol
, GError
**error
)
84 ThriftProtocolDecorator
*self
= THRIFT_PROTOCOL_DECORATOR (protocol
);
86 return THRIFT_PROTOCOL_GET_CLASS (self
->concrete_protocol
)->write_struct_end (self
->concrete_protocol
,
91 thrift_protocol_decorator_write_field_begin (ThriftProtocol
*protocol
,
93 const ThriftType field_type
,
94 const gint16 field_id
,
97 ThriftProtocolDecorator
*self
= THRIFT_PROTOCOL_DECORATOR (protocol
);
98 return THRIFT_PROTOCOL_GET_CLASS (self
->concrete_protocol
)->write_field_begin (self
->concrete_protocol
,
104 thrift_protocol_decorator_write_field_end (ThriftProtocol
*protocol
, GError
**error
)
106 ThriftProtocolDecorator
*self
= THRIFT_PROTOCOL_DECORATOR (protocol
);
108 return THRIFT_PROTOCOL_GET_CLASS (self
->concrete_protocol
)->write_field_end (self
->concrete_protocol
,
113 thrift_protocol_decorator_write_field_stop (ThriftProtocol
*protocol
, GError
**error
)
115 ThriftProtocolDecorator
*self
= THRIFT_PROTOCOL_DECORATOR (protocol
);
117 return THRIFT_PROTOCOL_GET_CLASS (self
->concrete_protocol
)->write_field_stop (self
->concrete_protocol
,
122 thrift_protocol_decorator_write_map_begin (ThriftProtocol
*protocol
,
123 const ThriftType key_type
,
124 const ThriftType value_type
,
125 const guint32 size
, GError
**error
)
127 ThriftProtocolDecorator
*self
= THRIFT_PROTOCOL_DECORATOR (protocol
);
129 return THRIFT_PROTOCOL_GET_CLASS (self
->concrete_protocol
)->write_map_begin (self
->concrete_protocol
,
130 key_type
, value_type
,
135 thrift_protocol_decorator_write_map_end (ThriftProtocol
*protocol
, GError
**error
)
137 ThriftProtocolDecorator
*self
= THRIFT_PROTOCOL_DECORATOR (protocol
);
139 return THRIFT_PROTOCOL_GET_CLASS (self
->concrete_protocol
)->write_map_end (self
->concrete_protocol
,
144 thrift_protocol_decorator_write_list_begin (ThriftProtocol
*protocol
,
145 const ThriftType element_type
,
146 const guint32 size
, GError
**error
)
148 ThriftProtocolDecorator
*self
= THRIFT_PROTOCOL_DECORATOR (protocol
);
150 return THRIFT_PROTOCOL_GET_CLASS (self
->concrete_protocol
)->write_list_begin (self
->concrete_protocol
,
156 thrift_protocol_decorator_write_list_end (ThriftProtocol
*protocol
, GError
**error
)
158 ThriftProtocolDecorator
*self
= THRIFT_PROTOCOL_DECORATOR (protocol
);
160 return THRIFT_PROTOCOL_GET_CLASS (self
->concrete_protocol
)->write_list_end (self
->concrete_protocol
,
165 thrift_protocol_decorator_write_set_begin (ThriftProtocol
*protocol
,
166 const ThriftType element_type
,
167 const guint32 size
, GError
**error
)
169 ThriftProtocolDecorator
*self
= THRIFT_PROTOCOL_DECORATOR (protocol
);
171 return THRIFT_PROTOCOL_GET_CLASS (self
->concrete_protocol
)->write_set_begin (self
->concrete_protocol
,
177 thrift_protocol_decorator_write_set_end (ThriftProtocol
*protocol
, GError
**error
)
179 ThriftProtocolDecorator
*self
= THRIFT_PROTOCOL_DECORATOR (protocol
);
181 return THRIFT_PROTOCOL_GET_CLASS (self
->concrete_protocol
)->write_set_end (self
->concrete_protocol
,
186 thrift_protocol_decorator_write_bool (ThriftProtocol
*protocol
,
187 const gboolean value
, GError
**error
)
189 ThriftProtocolDecorator
*self
= THRIFT_PROTOCOL_DECORATOR (protocol
);
191 return THRIFT_PROTOCOL_GET_CLASS (self
->concrete_protocol
)->write_bool (self
->concrete_protocol
, value
,
196 thrift_protocol_decorator_write_byte (ThriftProtocol
*protocol
, const gint8 value
,
199 ThriftProtocolDecorator
*self
= THRIFT_PROTOCOL_DECORATOR (protocol
);
201 return THRIFT_PROTOCOL_GET_CLASS (self
->concrete_protocol
)->write_byte (self
->concrete_protocol
, value
,
206 thrift_protocol_decorator_write_i16 (ThriftProtocol
*protocol
, const gint16 value
,
209 ThriftProtocolDecorator
*self
= THRIFT_PROTOCOL_DECORATOR (protocol
);
211 return THRIFT_PROTOCOL_GET_CLASS (self
->concrete_protocol
)->write_i16 (self
->concrete_protocol
, value
,
216 thrift_protocol_decorator_write_i32 (ThriftProtocol
*protocol
, const gint32 value
,
219 ThriftProtocolDecorator
*self
= THRIFT_PROTOCOL_DECORATOR (protocol
);
221 return THRIFT_PROTOCOL_GET_CLASS (self
->concrete_protocol
)->write_i32 (self
->concrete_protocol
, value
,
226 thrift_protocol_decorator_write_i64 (ThriftProtocol
*protocol
, const gint64 value
,
229 ThriftProtocolDecorator
*self
= THRIFT_PROTOCOL_DECORATOR (protocol
);
231 return THRIFT_PROTOCOL_GET_CLASS (self
->concrete_protocol
)->write_i64 (self
->concrete_protocol
, value
,
236 thrift_protocol_decorator_write_double (ThriftProtocol
*protocol
,
237 const gdouble value
, GError
**error
)
239 ThriftProtocolDecorator
*self
= THRIFT_PROTOCOL_DECORATOR (protocol
);
241 return THRIFT_PROTOCOL_GET_CLASS (self
->concrete_protocol
)->write_double (self
->concrete_protocol
,
246 thrift_protocol_decorator_write_string (ThriftProtocol
*protocol
,
247 const gchar
*str
, GError
**error
)
249 ThriftProtocolDecorator
*self
= THRIFT_PROTOCOL_DECORATOR (protocol
);
251 return THRIFT_PROTOCOL_GET_CLASS (self
->concrete_protocol
)->write_string (self
->concrete_protocol
, str
,
256 thrift_protocol_decorator_write_binary (ThriftProtocol
*protocol
, const gpointer buf
,
257 const guint32 len
, GError
**error
)
259 ThriftProtocolDecorator
*self
= THRIFT_PROTOCOL_DECORATOR (protocol
);
261 return THRIFT_PROTOCOL_GET_CLASS (self
->concrete_protocol
)->write_binary (self
->concrete_protocol
, buf
,
266 thrift_protocol_decorator_read_message_begin (ThriftProtocol
*protocol
,
268 ThriftMessageType
*message_type
,
269 gint32
*seqid
, GError
**error
)
271 ThriftProtocolDecorator
*self
= THRIFT_PROTOCOL_DECORATOR (protocol
);
273 return THRIFT_PROTOCOL_GET_CLASS (self
->concrete_protocol
)->read_message_begin (self
->concrete_protocol
,
279 thrift_protocol_decorator_read_message_end (ThriftProtocol
*protocol
,
282 ThriftProtocolDecorator
*self
= THRIFT_PROTOCOL_DECORATOR (protocol
);
284 return THRIFT_PROTOCOL_GET_CLASS (self
->concrete_protocol
)->read_message_end (self
->concrete_protocol
,
289 thrift_protocol_decorator_read_struct_begin (ThriftProtocol
*protocol
,
293 ThriftProtocolDecorator
*self
= THRIFT_PROTOCOL_DECORATOR (protocol
);
295 return THRIFT_PROTOCOL_GET_CLASS (self
->concrete_protocol
)->read_struct_begin (self
->concrete_protocol
,
301 thrift_protocol_decorator_read_struct_end (ThriftProtocol
*protocol
, GError
**error
)
303 ThriftProtocolDecorator
*self
= THRIFT_PROTOCOL_DECORATOR (protocol
);
305 return THRIFT_PROTOCOL_GET_CLASS (self
->concrete_protocol
)->read_struct_end (self
->concrete_protocol
,
310 thrift_protocol_decorator_read_field_begin (ThriftProtocol
*protocol
,
312 ThriftType
*field_type
,
316 ThriftProtocolDecorator
*self
= THRIFT_PROTOCOL_DECORATOR (protocol
);
318 return THRIFT_PROTOCOL_GET_CLASS (self
->concrete_protocol
)->read_field_begin (self
->concrete_protocol
,
326 thrift_protocol_decorator_read_field_end (ThriftProtocol
*protocol
,
329 ThriftProtocolDecorator
*self
= THRIFT_PROTOCOL_DECORATOR (protocol
);
331 return THRIFT_PROTOCOL_GET_CLASS (self
->concrete_protocol
)->read_field_end (self
->concrete_protocol
,
336 thrift_protocol_decorator_read_map_begin (ThriftProtocol
*protocol
,
337 ThriftType
*key_type
,
338 ThriftType
*value_type
, guint32
*size
,
341 ThriftProtocolDecorator
*self
= THRIFT_PROTOCOL_DECORATOR (protocol
);
343 return THRIFT_PROTOCOL_GET_CLASS (self
->concrete_protocol
)->read_map_begin (self
->concrete_protocol
,
351 thrift_protocol_decorator_read_map_end (ThriftProtocol
*protocol
, GError
**error
)
353 ThriftProtocolDecorator
*self
= THRIFT_PROTOCOL_DECORATOR (protocol
);
355 return THRIFT_PROTOCOL_GET_CLASS (self
->concrete_protocol
)->read_map_end (self
->concrete_protocol
,
360 thrift_protocol_decorator_read_list_begin (ThriftProtocol
*protocol
,
361 ThriftType
*element_type
,
362 guint32
*size
, GError
**error
)
364 ThriftProtocolDecorator
*self
= THRIFT_PROTOCOL_DECORATOR (protocol
);
366 return THRIFT_PROTOCOL_GET_CLASS (self
->concrete_protocol
)->read_list_begin (self
->concrete_protocol
,
372 thrift_protocol_decorator_read_list_end (ThriftProtocol
*protocol
, GError
**error
)
374 ThriftProtocolDecorator
*self
= THRIFT_PROTOCOL_DECORATOR (protocol
);
376 return THRIFT_PROTOCOL_GET_CLASS (self
->concrete_protocol
)->read_list_end (self
->concrete_protocol
,
381 thrift_protocol_decorator_read_set_begin (ThriftProtocol
*protocol
,
382 ThriftType
*element_type
,
383 guint32
*size
, GError
**error
)
385 ThriftProtocolDecorator
*self
= THRIFT_PROTOCOL_DECORATOR (protocol
);
387 return THRIFT_PROTOCOL_GET_CLASS (self
->concrete_protocol
)->read_set_begin (self
->concrete_protocol
,
393 thrift_protocol_decorator_read_set_end (ThriftProtocol
*protocol
, GError
**error
)
395 ThriftProtocolDecorator
*self
= THRIFT_PROTOCOL_DECORATOR (protocol
);
397 return THRIFT_PROTOCOL_GET_CLASS (self
->concrete_protocol
)->read_set_end (self
->concrete_protocol
,
402 thrift_protocol_decorator_read_bool (ThriftProtocol
*protocol
, gboolean
*value
,
405 ThriftProtocolDecorator
*self
= THRIFT_PROTOCOL_DECORATOR (protocol
);
407 return THRIFT_PROTOCOL_GET_CLASS (self
->concrete_protocol
)->read_bool (self
->concrete_protocol
, value
,
412 thrift_protocol_decorator_read_byte (ThriftProtocol
*protocol
, gint8
*value
,
415 ThriftProtocolDecorator
*self
= THRIFT_PROTOCOL_DECORATOR (protocol
);
417 return THRIFT_PROTOCOL_GET_CLASS (self
->concrete_protocol
)->read_byte (self
->concrete_protocol
, value
,
422 thrift_protocol_decorator_read_i16 (ThriftProtocol
*protocol
, gint16
*value
,
425 ThriftProtocolDecorator
*self
= THRIFT_PROTOCOL_DECORATOR (protocol
);
427 return THRIFT_PROTOCOL_GET_CLASS (self
->concrete_protocol
)->read_i16 (self
->concrete_protocol
, value
,
432 thrift_protocol_decorator_read_i32 (ThriftProtocol
*protocol
, gint32
*value
,
435 ThriftProtocolDecorator
*self
= THRIFT_PROTOCOL_DECORATOR (protocol
);
437 return THRIFT_PROTOCOL_GET_CLASS (self
->concrete_protocol
)->read_i32 (self
->concrete_protocol
, value
,
442 thrift_protocol_decorator_read_i64 (ThriftProtocol
*protocol
, gint64
*value
,
445 ThriftProtocolDecorator
*self
= THRIFT_PROTOCOL_DECORATOR (protocol
);
447 return THRIFT_PROTOCOL_GET_CLASS (self
->concrete_protocol
)->read_i64 (self
->concrete_protocol
, value
,
452 thrift_protocol_decorator_read_double (ThriftProtocol
*protocol
,
453 gdouble
*value
, GError
**error
)
455 ThriftProtocolDecorator
*self
= THRIFT_PROTOCOL_DECORATOR (protocol
);
457 return THRIFT_PROTOCOL_GET_CLASS (self
->concrete_protocol
)->read_double (self
->concrete_protocol
, value
,
462 thrift_protocol_decorator_read_string (ThriftProtocol
*protocol
,
463 gchar
**str
, GError
**error
)
465 ThriftProtocolDecorator
*self
= THRIFT_PROTOCOL_DECORATOR (protocol
);
467 return THRIFT_PROTOCOL_GET_CLASS (self
->concrete_protocol
)->read_string (self
->concrete_protocol
, str
,
472 thrift_protocol_decorator_read_binary (ThriftProtocol
*protocol
, gpointer
*buf
,
473 guint32
*len
, GError
**error
)
475 ThriftProtocolDecorator
*self
= THRIFT_PROTOCOL_DECORATOR (protocol
);
477 return THRIFT_PROTOCOL_GET_CLASS (self
->concrete_protocol
)->read_binary (self
->concrete_protocol
, buf
,
483 thrift_protocol_decorator_set_property (GObject
*object
,
488 ThriftProtocolDecorator
*self
= THRIFT_PROTOCOL_DECORATOR (object
);
492 case PROP_THRIFT_TYPE_PROTOCOL_DECORATOR_CONCRETE_PROTOCOL
:
493 self
->concrete_protocol
= g_value_dup_object (value
);
497 /* We don't have any other property... */
498 G_OBJECT_WARN_INVALID_PROPERTY_ID (object
, property_id
, pspec
);
504 thrift_protocol_decorator_get_property (GObject
*object
,
509 ThriftProtocolDecorator
*self
= THRIFT_PROTOCOL_DECORATOR (object
);
513 case PROP_THRIFT_TYPE_PROTOCOL_DECORATOR_CONCRETE_PROTOCOL
:
514 g_value_set_object (value
, self
->concrete_protocol
);
518 /* We don't have any other property... */
519 G_OBJECT_WARN_INVALID_PROPERTY_ID (object
, property_id
, pspec
);
526 thrift_protocol_decorator_get_concrete_protocol(ThriftProtocolDecorator
*protocol
)
528 ThriftProtocol
*retval
= NULL
;
529 if(!THRIFT_IS_PROTOCOL_DECORATOR(protocol
)){
530 g_warning("The type is not protocol decorator");
533 ThriftProtocolDecorator
*self
= THRIFT_PROTOCOL_DECORATOR(protocol
);
534 g_debug("Getting concrete protocol from %p -> %p", (void *)self
, (void *)self
->concrete_protocol
);
541 thrift_protocol_decorator_init (ThriftProtocolDecorator
*protocol
)
543 protocol
->concrete_protocol
= NULL
;
547 thrift_protocol_decorator_dispose (GObject
*gobject
)
549 ThriftProtocolDecorator
*self
= THRIFT_PROTOCOL_DECORATOR (gobject
);
551 g_clear_object(&self
->concrete_protocol
);
553 /* Always chain up to the parent class; there is no need to check if
554 * the parent class implements the dispose() virtual function: it is
555 * always guaranteed to do so
557 G_OBJECT_CLASS (thrift_protocol_decorator_parent_class
)->dispose(gobject
);
560 /* initialize the class */
562 thrift_protocol_decorator_class_init (ThriftProtocolDecoratorClass
*klass
)
564 ThriftProtocolClass
*cls
= THRIFT_PROTOCOL_CLASS (klass
);
565 GObjectClass
*object_class
= G_OBJECT_CLASS (klass
);
566 object_class
->set_property
= thrift_protocol_decorator_set_property
;
567 object_class
->get_property
= thrift_protocol_decorator_get_property
;
568 object_class
->dispose
= thrift_protocol_decorator_dispose
;
570 thrift_protocol_decorator_obj_properties
[PROP_THRIFT_TYPE_PROTOCOL_DECORATOR_CONCRETE_PROTOCOL
] =
571 g_param_spec_object ("protocol",
573 "Set the protocol to be implemented", THRIFT_TYPE_PROTOCOL
,
574 (G_PARAM_CONSTRUCT_ONLY
| G_PARAM_READWRITE
));
576 g_object_class_install_properties (object_class
,
577 PROP_THRIFT_TYPE_PROTOCOL_DECORATOR_END
,
578 thrift_protocol_decorator_obj_properties
);
580 g_debug("Current decorator write_message_begin addr %p, new %p", cls
->write_message_begin
, thrift_protocol_decorator_write_message_begin
);
582 cls
->write_message_begin
= thrift_protocol_decorator_write_message_begin
;
583 cls
->write_message_end
= thrift_protocol_decorator_write_message_end
;
584 cls
->write_struct_begin
= thrift_protocol_decorator_write_struct_begin
;
585 cls
->write_struct_end
= thrift_protocol_decorator_write_struct_end
;
586 cls
->write_field_begin
= thrift_protocol_decorator_write_field_begin
;
587 cls
->write_field_end
= thrift_protocol_decorator_write_field_end
;
588 cls
->write_field_stop
= thrift_protocol_decorator_write_field_stop
;
589 cls
->write_map_begin
= thrift_protocol_decorator_write_map_begin
;
590 cls
->write_map_end
= thrift_protocol_decorator_write_map_end
;
591 cls
->write_list_begin
= thrift_protocol_decorator_write_list_begin
;
592 cls
->write_list_end
= thrift_protocol_decorator_write_list_end
;
593 cls
->write_set_begin
= thrift_protocol_decorator_write_set_begin
;
594 cls
->write_set_end
= thrift_protocol_decorator_write_set_end
;
595 cls
->write_bool
= thrift_protocol_decorator_write_bool
;
596 cls
->write_byte
= thrift_protocol_decorator_write_byte
;
597 cls
->write_i16
= thrift_protocol_decorator_write_i16
;
598 cls
->write_i32
= thrift_protocol_decorator_write_i32
;
599 cls
->write_i64
= thrift_protocol_decorator_write_i64
;
600 cls
->write_double
= thrift_protocol_decorator_write_double
;
601 cls
->write_string
= thrift_protocol_decorator_write_string
;
602 cls
->write_binary
= thrift_protocol_decorator_write_binary
;
603 cls
->read_message_begin
= thrift_protocol_decorator_read_message_begin
;
604 cls
->read_message_end
= thrift_protocol_decorator_read_message_end
;
605 cls
->read_struct_begin
= thrift_protocol_decorator_read_struct_begin
;
606 cls
->read_struct_end
= thrift_protocol_decorator_read_struct_end
;
607 cls
->read_field_begin
= thrift_protocol_decorator_read_field_begin
;
608 cls
->read_field_end
= thrift_protocol_decorator_read_field_end
;
609 cls
->read_map_begin
= thrift_protocol_decorator_read_map_begin
;
610 cls
->read_map_end
= thrift_protocol_decorator_read_map_end
;
611 cls
->read_list_begin
= thrift_protocol_decorator_read_list_begin
;
612 cls
->read_list_end
= thrift_protocol_decorator_read_list_end
;
613 cls
->read_set_begin
= thrift_protocol_decorator_read_set_begin
;
614 cls
->read_set_end
= thrift_protocol_decorator_read_set_end
;
615 cls
->read_bool
= thrift_protocol_decorator_read_bool
;
616 cls
->read_byte
= thrift_protocol_decorator_read_byte
;
617 cls
->read_i16
= thrift_protocol_decorator_read_i16
;
618 cls
->read_i32
= thrift_protocol_decorator_read_i32
;
619 cls
->read_i64
= thrift_protocol_decorator_read_i64
;
620 cls
->read_double
= thrift_protocol_decorator_read_double
;
621 cls
->read_string
= thrift_protocol_decorator_read_string
;
622 cls
->read_binary
= thrift_protocol_decorator_read_binary
;