You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@thrift.apache.org by ro...@apache.org on 2010/10/27 14:30:13 UTC
svn commit: r1027933 [3/6] - in /incubator/thrift/trunk: ./ compiler/cpp/
compiler/cpp/src/generate/ compiler/cpp/src/parse/ lib/ lib/c_glib/
lib/c_glib/src/ lib/c_glib/src/processor/ lib/c_glib/src/protocol/
lib/c_glib/src/server/ lib/c_glib/src/trans...
Modified: incubator/thrift/trunk/compiler/cpp/src/parse/t_program.h
URL: http://svn.apache.org/viewvc/incubator/thrift/trunk/compiler/cpp/src/parse/t_program.h?rev=1027933&r1=1027932&r2=1027933&view=diff
==============================================================================
--- incubator/thrift/trunk/compiler/cpp/src/parse/t_program.h (original)
+++ incubator/thrift/trunk/compiler/cpp/src/parse/t_program.h Wed Oct 27 12:30:11 2010
@@ -209,6 +209,14 @@ class t_program : public t_doc {
return cpp_includes_;
}
+ void add_c_include(std::string path) {
+ c_includes_.push_back(path);
+ }
+
+ const std::vector<std::string>& get_c_includes() {
+ return c_includes_;
+ }
+
private:
// File path
@@ -247,6 +255,9 @@ class t_program : public t_doc {
// C++ extra includes
std::vector<std::string> cpp_includes_;
+ // C extra includes
+ std::vector<std::string> c_includes_;
+
};
#endif
Modified: incubator/thrift/trunk/configure.ac
URL: http://svn.apache.org/viewvc/incubator/thrift/trunk/configure.ac?rev=1027933&r1=1027932&r2=1027933&view=diff
==============================================================================
--- incubator/thrift/trunk/configure.ac (original)
+++ incubator/thrift/trunk/configure.ac Wed Oct 27 12:30:11 2010
@@ -99,6 +99,16 @@ AM_CONDITIONAL([WITH_CPP], [test "$have_
AM_CONDITIONAL([AMX_HAVE_LIBEVENT], [test "$have_libevent" = "yes"])
AM_CONDITIONAL([AMX_HAVE_ZLIB], [test "$have_zlib" = "yes"])
+AX_THRIFT_LIB(c_glib, [C (GLib)], no)
+if test "$with_c_glib" = "yes"; then
+ PKG_CHECK_MODULES([GLIB], [glib-2.0 >= 2.0], have_glib2=yes, have_glib2=no)
+ PKG_CHECK_MODULES([GOBJECT], [gobject-2.0 >= 2.0], have_gobject2=yes, have_gobject2=no)
+ if test "$have_glib2" = "yes" -a "$have_gobject2" = "yes" ; then
+ have_c_glib="yes"
+ fi
+fi
+AM_CONDITIONAL(WITH_C_GLIB, [test "$have_glib2" = "yes" -a "$have_gobject2" = "yes"])
+
AX_THRIFT_LIB(csharp, [C#], yes)
if test "$with_csharp" = "yes"; then
PKG_CHECK_MODULES(MONO, mono >= 2.0.0, net_3_5=yes, net_3_5=no)
@@ -279,6 +289,7 @@ AC_CHECK_DECL([AI_ADDRCONFIG], [],
])
AC_FUNC_ALLOCA
+AC_FUNC_FORK
AC_FUNC_MALLOC
AC_FUNC_MEMCMP
AC_FUNC_REALLOC
@@ -305,6 +316,7 @@ AC_CHECK_FUNCS([strstr])
AC_CHECK_FUNCS([strtol])
AC_CHECK_FUNCS([sqrt])
dnl The following functions are optional.
+AC_CHECK_FUNCS([alarm])
AC_CHECK_FUNCS([clock_gettime])
AC_CHECK_FUNCS([sched_get_priority_min])
AC_CHECK_FUNCS([sched_get_priority_max])
@@ -323,6 +335,8 @@ fi
AX_THRIFT_GEN(cpp, [C++], yes)
AM_CONDITIONAL([THRIFT_GEN_cpp], [test "$ax_thrift_gen_cpp" = "yes"])
+AX_THRIFT_GEN(c_glib, [C (GLib)], yes)
+AM_CONDITIONAL([THRIFT_GEN_c_glib], [test "$ax_thrift_gen_c_glib" = "yes"])
AX_THRIFT_GEN(java, [Java], yes)
AM_CONDITIONAL([THRIFT_GEN_java], [test "$ax_thrift_gen_java" = "yes"])
AX_THRIFT_GEN(as3, [AS3], yes)
@@ -356,6 +370,29 @@ AM_CONDITIONAL([THRIFT_GEN_js], [test "$
AX_THRIFT_GEN(javame, [JavaME], yes)
AM_CONDITIONAL([THRIFT_GEN_javame], [test "$ax_thrift_gen_javame" = "yes"])
+# --- Coverage hooks ---
+
+AC_ARG_ENABLE(coverage,
+ [ --enable-coverage turn on -fprofile-arcs -ftest-coverage],
+ [case "${enableval}" in
+ yes) ENABLE_COVERAGE=1 ;;
+ no) ENABLE_COVERAGE=0 ;;
+ *) AC_MSG_ERROR(bad value ${enableval} for --enable-cov) ;;
+ esac],
+ [ENABLE_COVERAGE=2])
+
+if test "x[$]ENABLE_COVERAGE" = "x1"; then
+ AC_MSG_WARN(enable coverage)
+ GCOV_CFLAGS="`echo \"[$]CFLAGS\" | perl -pe 's/-O\d+//g;'` -fprofile-arcs -ftest-coverage"
+ GCOV_CXXFLAGS="`echo \"[$]CXXFLAGS\" | perl -pe 's/-O\d+//g;'` -fprofile-arcs -ftest-coverage"
+ GCOV_LDFLAGS="-XCClinker -fprofile-arcs -XCClinker -ftest-coverage"
+fi
+
+AC_SUBST(ENABLE_COVERAGE)
+AC_SUBST(GCOV_CFLAGS)
+AC_SUBST(GCOV_CXXFLAGS)
+AC_SUBST(GCOV_LDFLAGS)
+
AC_CONFIG_HEADERS(config.h:config.hin)
AC_CONFIG_FILES([
@@ -368,6 +405,9 @@ AC_CONFIG_FILES([
lib/cpp/thrift-nb.pc
lib/cpp/thrift-z.pc
lib/cpp/thrift.pc
+ lib/c_glib/Makefile
+ lib/c_glib/thrift_c_glib.pc
+ lib/c_glib/test/Makefile
lib/csharp/Makefile
lib/erl/Makefile
lib/erl/src/Makefile
@@ -385,6 +425,9 @@ AC_CONFIG_FILES([
test/rb/Makefile
])
+AC_CONFIG_FILES([lib/c_glib/test/test-wrapper.sh],
+ [chmod +x lib/c_glib/test/test-wrapper.sh])
+
AC_OUTPUT
@@ -394,6 +437,7 @@ echo
echo "Building code generators ..... :$thrift_generators"
echo
echo "Building C++ Library ......... : $have_cpp"
+echo "Building C (GLib) Library .... : $have_c_glib"
echo "Building Java Library ........ : $have_java"
echo "Building C# Library .......... : $have_csharp"
echo "Building Python Library ...... : $have_python"
Modified: incubator/thrift/trunk/lib/Makefile.am
URL: http://svn.apache.org/viewvc/incubator/thrift/trunk/lib/Makefile.am?rev=1027933&r1=1027932&r2=1027933&view=diff
==============================================================================
--- incubator/thrift/trunk/lib/Makefile.am (original)
+++ incubator/thrift/trunk/lib/Makefile.am Wed Oct 27 12:30:11 2010
@@ -23,6 +23,10 @@ if WITH_CPP
SUBDIRS += cpp
endif
+if WITH_C_GLIB
+SUBDIRS += c_glib
+endif
+
if WITH_MONO
SUBDIRS += csharp
endif
Propchange: incubator/thrift/trunk/lib/c_glib/
------------------------------------------------------------------------------
--- svn:ignore (added)
+++ svn:ignore Wed Oct 27 12:30:11 2010
@@ -0,0 +1,12 @@
+*.gcda
+*.gcno
+*.la
+*.lo
+*.loT
+*.o
+.deps
+.libs
+Makefile.in
+Makefile
+thriftc.pc
+thrift_c_glib.pc
Added: incubator/thrift/trunk/lib/c_glib/Makefile.am
URL: http://svn.apache.org/viewvc/incubator/thrift/trunk/lib/c_glib/Makefile.am?rev=1027933&view=auto
==============================================================================
--- incubator/thrift/trunk/lib/c_glib/Makefile.am (added)
+++ incubator/thrift/trunk/lib/c_glib/Makefile.am Wed Oct 27 12:30:11 2010
@@ -0,0 +1,93 @@
+#
+# Licensed to the Apache Software Foundation (ASF) under one
+# or more contributor license agreements. See the NOTICE file
+# distributed with this work for additional information
+# regarding copyright ownership. The ASF licenses this file
+# to you under the Apache License, Version 2.0 (the
+# "License"); you may not use this file except in compliance
+# with the License. You may obtain a copy of the License at
+#
+# http://www.apache.org/licenses/LICENSE-2.0
+#
+# Unless required by applicable law or agreed to in writing,
+# software distributed under the License is distributed on an
+# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+# KIND, either express or implied. See the License for the
+# specific language governing permissions and limitations
+# under the License.
+#
+
+SUBDIRS = . test
+
+pkgconfigdir = $(libdir)/pkgconfig
+
+lib_LTLIBRARIES = libthrift_c_glib.la
+pkgconfig_DATA = thrift_c_glib.pc
+
+common_cflags = -g -Wall -W -Werror -Isrc $(GLIB_CFLAGS)
+common_ldflags = -g -Wall -W $(GLIB_LDFLAGS) @GCOV_LDFLAGS@
+
+# this removes optimizations and adds coverage flags
+CFLAGS = @GCOV_CFLAGS@
+
+# Define the source files for the module
+
+libthrift_c_glib_la_SOURCES = src/thrift.c \
+ src/thrift_struct.c \
+ src/thrift_application_exception.c \
+ src/processor/thrift_processor.c \
+ src/protocol/thrift_protocol.c \
+ src/protocol/thrift_protocol_factory.c \
+ src/protocol/thrift_binary_protocol.c \
+ src/protocol/thrift_binary_protocol_factory.c \
+ src/transport/thrift_transport.c \
+ src/transport/thrift_transport_factory.c \
+ src/transport/thrift_socket.c \
+ src/transport/thrift_server_transport.c \
+ src/transport/thrift_server_socket.c \
+ src/transport/thrift_buffered_transport.c \
+ src/transport/thrift_framed_transport.c \
+ src/transport/thrift_memory_buffer.c \
+ src/server/thrift_server.c \
+ src/server/thrift_simple_server.c
+
+libthrift_c_glib_la_CFLAGS = $(common_cflags)
+
+include_thriftdir = $(includedir)/thrift
+include_thrift_HEADERS = \
+ $(top_builddir)/config.h \
+ src/thrift.h \
+ src/thrift_application_exception.h \
+ src/thrift_struct.h
+
+include_protocoldir = $(include_thriftdir)/protocol
+include_protocol_HEADERS = src/protocol/thrift_protocol.h \
+ src/protocol/thrift_protocol_factory.h \
+ src/protocol/thrift_binary_protocol.h \
+ src/protocol/thrift_binary_protocol_factory.h
+
+include_transportdir = $(include_thriftdir)/transport
+include_transport_HEADERS = src/transport/thrift_buffered_transport.h \
+ src/transport/thrift_framed_transport.h \
+ src/transport/thrift_memory_buffer.h \
+ src/transport/thrift_server_socket.h \
+ src/transport/thrift_server_transport.h \
+ src/transport/thrift_socket.h \
+ src/transport/thrift_transport.h \
+ src/transport/thrift_transport_factory.h
+
+include_serverdir = $(include_thriftdir)/server
+include_server_HEADERS = src/server/thrift_server.h \
+ src/server/thrift_simple_server.h
+
+include_processordir = $(include_thriftdir)/processor
+include_processor_HEADERS = src/processor/thrift_processor.h
+
+
+EXTRA_DIST = \
+ README \
+ thrift_c_glib.pc.in
+
+CLEANFILES = \
+ *.gcno \
+ *.gcda
Added: incubator/thrift/trunk/lib/c_glib/src/processor/thrift_processor.c
URL: http://svn.apache.org/viewvc/incubator/thrift/trunk/lib/c_glib/src/processor/thrift_processor.c?rev=1027933&view=auto
==============================================================================
--- incubator/thrift/trunk/lib/c_glib/src/processor/thrift_processor.c (added)
+++ incubator/thrift/trunk/lib/c_glib/src/processor/thrift_processor.c Wed Oct 27 12:30:11 2010
@@ -0,0 +1,50 @@
+#include "thrift.h"
+#include "processor/thrift_processor.h"
+
+/* forward declarations */
+static void thrift_processor_class_init (ThriftProcessorClass *cls);
+
+/* define ThriftProcessorClass's type */
+GType
+thrift_processor_get_type (void)
+{
+ static GType type = 0;
+
+ if (type == 0)
+ {
+ static const GTypeInfo info =
+ {
+ sizeof (ThriftProcessorClass),
+ NULL, /* base_init */
+ NULL, /* base_finalize */
+ (GClassInitFunc) thrift_processor_class_init,
+ NULL, /* class_finalize */
+ NULL, /* class_data */
+ sizeof (ThriftProcessor),
+ 0, /* n_preallocs */
+ NULL, /* instance_init */
+ NULL, /* value_table */
+ };
+
+ type = g_type_register_static (G_TYPE_OBJECT, "ThriftProcessor",
+ &info, G_TYPE_FLAG_ABSTRACT);
+ }
+
+ return type;
+}
+
+/* class initializer for ThriftProcessor */
+static void
+thrift_processor_class_init (ThriftProcessorClass *cls)
+{
+ /* set these as virtual methods to be implemented by a subclass */
+ cls->process = thrift_processor_process;
+}
+
+gboolean
+thrift_processor_process (ThriftProcessor *processor, ThriftProtocol *in,
+ ThriftProtocol *out)
+{
+ return THRIFT_PROCESSOR_GET_CLASS (processor)->process (processor, in, out);
+}
+
Added: incubator/thrift/trunk/lib/c_glib/src/processor/thrift_processor.h
URL: http://svn.apache.org/viewvc/incubator/thrift/trunk/lib/c_glib/src/processor/thrift_processor.h?rev=1027933&view=auto
==============================================================================
--- incubator/thrift/trunk/lib/c_glib/src/processor/thrift_processor.h (added)
+++ incubator/thrift/trunk/lib/c_glib/src/processor/thrift_processor.h Wed Oct 27 12:30:11 2010
@@ -0,0 +1,59 @@
+#ifndef _THRIFT_PROCESSOR_H
+#define _THRIFT_PROCESSOR_H
+
+#include <glib-object.h>
+
+#include "protocol/thrift_protocol.h"
+
+/*! \file thrift_processor.h
+ * \brief Abstract class for Thrift processors.
+ */
+
+/* type macros */
+#define THRIFT_TYPE_PROCESSOR (thrift_processor_get_type ())
+#define THRIFT_PROCESSOR(obj) (G_TYPE_CHECK_INSTANCE_CAST ((obj), \
+ THRIFT_TYPE_PROCESSOR, ThriftProcessor))
+#define THRIFT_IS_PROCESSOR(obj) (G_TYPE_CHECK_INSTANCE_TYPE ((obj), \
+ THRIFT_TYPE_PROCESSOR))
+#define THRIFT_PROCESSOR_CLASS(c) (G_TYPE_CHECK_CLASS_CAST ((c), \
+ THRIFT_TYPE_PROCESSOR, \
+ ThriftProcessorClass))
+#define THRIFT_IS_PROCESSOR_CLASS(c) (G_TYPE_CHECK_CLASS_TYPE ((c), \
+ THRIFT_TYPE_PROCESSOR))
+#define THRIFT_PROCESSOR_GET_CLASS(obj) (G_TYPE_INSTANCE_GET_CLASS ((obj), \
+ THRIFT_TYPE_PROCESSOR, \
+ ThriftProcessorClass))
+
+/*!
+ * Thrift Processorobject
+ */
+struct _ThriftProcessor
+{
+ GObject parent;
+};
+typedef struct _ThriftProcessor ThriftProcessor;
+
+/*!
+ * Thrift Processor class
+ */
+struct _ThriftProcessorClass
+{
+ GObjectClass parent;
+
+ /* vtable */
+ gboolean (*process) (ThriftProcessor *processor, ThriftProtocol *in,
+ ThriftProtocol *out);
+};
+typedef struct _ThriftProcessorClass ThriftProcessorClass;
+
+/* used by THRIFT_TYPE_PROCESSOR */
+GType thrift_processor_get_type (void);
+
+/*!
+ * Processes the request.
+ * \public \memberof ThriftProcessorClass
+ */
+gboolean thrift_processor_process (ThriftProcessor *processor,
+ ThriftProtocol *in, ThriftProtocol *out);
+
+#endif /* _THRIFT_PROCESSOR_H */
Added: incubator/thrift/trunk/lib/c_glib/src/protocol/thrift_binary_protocol.c
URL: http://svn.apache.org/viewvc/incubator/thrift/trunk/lib/c_glib/src/protocol/thrift_binary_protocol.c?rev=1027933&view=auto
==============================================================================
--- incubator/thrift/trunk/lib/c_glib/src/protocol/thrift_binary_protocol.c (added)
+++ incubator/thrift/trunk/lib/c_glib/src/protocol/thrift_binary_protocol.c Wed Oct 27 12:30:11 2010
@@ -0,0 +1,983 @@
+#include <string.h>
+#include <stdio.h>
+
+#include "thrift.h"
+#include "protocol/thrift_protocol.h"
+#include "protocol/thrift_binary_protocol.h"
+
+/* forward declarations */
+static guint64 thrift_bitwise_cast_guint64 (gdouble v);
+static gdouble thrift_bitwise_cast_gdouble (guint64 v);
+static void thrift_binary_protocol_class_init (ThriftProtocolClass *cls);
+
+gint32 thrift_binary_protocol_write_message_begin (ThriftProtocol *protocol,
+ const gchar *name, const ThriftMessageType message_type,
+ const gint32 seqid, GError **error);
+gint32 thrift_binary_protocol_write_message_end (ThriftProtocol *protocol,
+ GError **error);
+gint32 thrift_binary_protocol_write_struct_begin (ThriftProtocol *protocol,
+ const gchar *name,
+ GError **error);
+gint32 thrift_binary_protocol_write_struct_end (ThriftProtocol *protocol,
+ GError **error);
+gint32 thrift_binary_protocol_write_field_begin (ThriftProtocol *protocol,
+ const gchar *name,
+ const ThriftType field_type,
+ const gint16 field_id,
+ GError **error);
+gint32 thrift_binary_protocol_write_field_end (ThriftProtocol *protocol,
+ GError **error);
+gint32 thrift_binary_protocol_write_field_stop (ThriftProtocol *protocol,
+ GError **error);
+gint32 thrift_binary_protocol_write_map_begin (ThriftProtocol *protocol,
+ const ThriftType key_type,
+ const ThriftType value_type,
+ const guint32 size,
+ GError **error);
+gint32 thrift_binary_protocol_write_map_end (ThriftProtocol *protocol,
+ GError **error);
+gint32 thrift_binary_protocol_write_list_begin (ThriftProtocol *protocol,
+ const ThriftType element_type,
+ const guint32 size,
+ GError **error);
+gint32 thrift_binary_protocol_write_list_end (ThriftProtocol *protocol,
+ GError **error);
+gint32 thrift_binary_protocol_write_set_begin (ThriftProtocol *protocol,
+ const ThriftType element_type,
+ const guint32 size,
+ GError **error);
+gint32 thrift_binary_protocol_write_set_end (ThriftProtocol *protocol,
+ GError **error);
+gint32 thrift_binary_protocol_write_bool (ThriftProtocol *protocol,
+ const gboolean value, GError **error);
+gint32 thrift_binary_protocol_write_byte (ThriftProtocol *protocol,
+ const gint8 value, GError **error);
+gint32 thrift_binary_protocol_write_i16 (ThriftProtocol *protocol,
+ const gint16 value, GError **error);
+gint32 thrift_binary_protocol_write_i32 (ThriftProtocol *protocol,
+ const gint32 value, GError **error);
+gint32 thrift_binary_protocol_write_i64 (ThriftProtocol *protocol,
+ const gint64 value, GError **error);
+gint32 thrift_binary_protocol_write_double (ThriftProtocol *protocol,
+ const gdouble value,
+ GError **error);
+gint32 thrift_binary_protocol_write_string (ThriftProtocol *protocol,
+ const gchar *str, GError **error);
+gint32 thrift_binary_protocol_write_binary (ThriftProtocol *protocol,
+ const gpointer buf,
+ const guint32 len, GError **error);
+gint32 thrift_binary_protocol_read_message_begin (
+ ThriftProtocol *protocol, gchar **name,
+ ThriftMessageType *message_type, gint32 *seqid, GError **error);
+gint32 thrift_binary_protocol_read_message_end (ThriftProtocol *protocol,
+ GError **error);
+gint32 thrift_binary_protocol_read_struct_begin (ThriftProtocol *protocol,
+ gchar **name,
+ GError **error);
+gint32 thrift_binary_protocol_read_struct_end (ThriftProtocol *protocol,
+ GError **error);
+gint32 thrift_binary_protocol_read_field_begin (ThriftProtocol *protocol,
+ gchar **name,
+ ThriftType *field_type,
+ gint16 *field_id,
+ GError **error);
+gint32 thrift_binary_protocol_read_field_end (ThriftProtocol *protocol,
+ GError **error);
+gint32 thrift_binary_protocol_read_map_begin (ThriftProtocol *protocol,
+ ThriftType *key_type,
+ ThriftType *value_type,
+ guint32 *size,
+ GError **error);
+gint32 thrift_binary_protocol_read_map_end (ThriftProtocol *protocol,
+ GError **error);
+gint32 thrift_binary_protocol_read_list_begin (ThriftProtocol *protocol,
+ ThriftType *element_type,
+ guint32 *size, GError **error);
+gint32 thrift_binary_protocol_read_list_end (ThriftProtocol *protocol,
+ GError **error);
+gint32 thrift_binary_protocol_read_set_begin (ThriftProtocol *protocol,
+ ThriftType *element_type,
+ guint32 *size, GError **error);
+gint32 thrift_binary_protocol_read_set_end (ThriftProtocol *protocol,
+ GError **error);
+gint32 thrift_binary_protocol_read_bool (ThriftProtocol *protocol,
+ gboolean *value, GError **error);
+gint32 thrift_binary_protocol_read_byte (ThriftProtocol *protocol, gint8 *value,
+ GError **error);
+gint32 thrift_binary_protocol_read_i16 (ThriftProtocol *protocol, gint16 *value,
+ GError **error);
+gint32 thrift_binary_protocol_read_i32 (ThriftProtocol *protocol, gint32 *value,
+ GError **error);
+gint32 thrift_binary_protocol_read_i64 (ThriftProtocol *protocol, gint64 *value,
+ GError **error);
+gint32 thrift_binary_protocol_read_double (ThriftProtocol *protocol,
+ gdouble *value, GError **error);
+gint32 thrift_binary_protocol_read_string (ThriftProtocol *protocol,
+ gchar **str, GError **error);
+gint32 thrift_binary_protocol_read_binary (ThriftProtocol *protocol,
+ gpointer *buf, guint32 *len,
+ GError **error);
+
+static guint64
+thrift_bitwise_cast_guint64 (gdouble v)
+{
+ union {
+ gdouble from;
+ guint64 to;
+ } u;
+ u.from = v;
+ return u.to;
+}
+
+static gdouble
+thrift_bitwise_cast_gdouble (guint64 v)
+{
+ union {
+ guint64 from;
+ gdouble to;
+ } u;
+ u.from = v;
+ return u.to;
+}
+
+GType
+thrift_binary_protocol_get_type (void)
+{
+ static GType type = 0;
+
+ if (type == 0)
+ {
+ static const GTypeInfo info =
+ {
+ sizeof (ThriftBinaryProtocolClass),
+ NULL, /* base_init */
+ NULL, /* base_finalize */
+ (GClassInitFunc) thrift_binary_protocol_class_init,
+ NULL, /* class_finalize */
+ NULL, /* class_data */
+ sizeof (ThriftBinaryProtocol),
+ 0, /* n_preallocs */
+ NULL, /* instance_init */
+ NULL, /* value_table */
+ };
+
+ type = g_type_register_static (THRIFT_TYPE_PROTOCOL,
+ "ThriftBinaryProtocolType",
+ &info, 0);
+ }
+
+ return type;
+}
+
+/* initialize the class */
+static void
+thrift_binary_protocol_class_init (ThriftProtocolClass *cls)
+{
+ cls->write_message_begin = thrift_binary_protocol_write_message_begin;
+ cls->write_message_end = thrift_binary_protocol_write_message_end;
+ cls->write_struct_begin = thrift_binary_protocol_write_struct_begin;
+ cls->write_struct_end = thrift_binary_protocol_write_struct_end;
+ cls->write_field_begin = thrift_binary_protocol_write_field_begin;
+ cls->write_field_end = thrift_binary_protocol_write_field_end;
+ cls->write_field_stop = thrift_binary_protocol_write_field_stop;
+ cls->write_map_begin = thrift_binary_protocol_write_map_begin;
+ cls->write_map_end = thrift_binary_protocol_write_map_end;
+ cls->write_list_begin = thrift_binary_protocol_write_list_begin;
+ cls->write_list_end = thrift_binary_protocol_write_list_end;
+ cls->write_set_begin = thrift_binary_protocol_write_set_begin;
+ cls->write_set_end = thrift_binary_protocol_write_set_end;
+ cls->write_bool = thrift_binary_protocol_write_bool;
+ cls->write_byte = thrift_binary_protocol_write_byte;
+ cls->write_i16 = thrift_binary_protocol_write_i16;
+ cls->write_i32 = thrift_binary_protocol_write_i32;
+ cls->write_i64 = thrift_binary_protocol_write_i64;
+ cls->write_double = thrift_binary_protocol_write_double;
+ cls->write_string = thrift_binary_protocol_write_string;
+ cls->write_binary = thrift_binary_protocol_write_binary;
+ cls->read_message_begin = thrift_binary_protocol_read_message_begin;
+ cls->read_message_end = thrift_binary_protocol_read_message_end;
+ cls->read_struct_begin = thrift_binary_protocol_read_struct_begin;
+ cls->read_struct_end = thrift_binary_protocol_read_struct_end;
+ cls->read_field_begin = thrift_binary_protocol_read_field_begin;
+ cls->read_field_end = thrift_binary_protocol_read_field_end;
+ cls->read_map_begin = thrift_binary_protocol_read_map_begin;
+ cls->read_map_end = thrift_binary_protocol_read_map_end;
+ cls->read_list_begin = thrift_binary_protocol_read_list_begin;
+ cls->read_list_end = thrift_binary_protocol_read_list_end;
+ cls->read_set_begin = thrift_binary_protocol_read_set_begin;
+ cls->read_set_end = thrift_binary_protocol_read_set_end;
+ cls->read_bool = thrift_binary_protocol_read_bool;
+ cls->read_byte = thrift_binary_protocol_read_byte;
+ cls->read_i16 = thrift_binary_protocol_read_i16;
+ cls->read_i32 = thrift_binary_protocol_read_i32;
+ cls->read_i64 = thrift_binary_protocol_read_i64;
+ cls->read_double = thrift_binary_protocol_read_double;
+ cls->read_string = thrift_binary_protocol_read_string;
+ cls->read_binary = thrift_binary_protocol_read_binary;
+}
+
+gint32
+thrift_binary_protocol_write_message_begin (ThriftProtocol *protocol,
+ const gchar *name, const ThriftMessageType message_type,
+ const gint32 seqid, GError **error)
+{
+ g_return_val_if_fail (THRIFT_IS_BINARY_PROTOCOL (protocol), -1);
+
+ gint32 version = (THRIFT_BINARY_PROTOCOL_VERSION_1)
+ | ((gint32) message_type);
+ gint32 ret;
+ gint32 xfer = 0;
+
+ if ((ret = thrift_protocol_write_i32 (protocol, version, error)) < 0)
+ {
+ return -1;
+ }
+ xfer += ret;
+ if ((ret = thrift_protocol_write_string (protocol, name, error)) < 0)
+ {
+ return -1;
+ }
+ xfer += ret;
+ if ((ret = thrift_protocol_write_i32 (protocol, seqid, error)) < 0)
+ {
+ return -1;
+ }
+ xfer += ret;
+ return xfer;
+}
+
+gint32
+thrift_binary_protocol_write_message_end (ThriftProtocol *protocol,
+ GError **error)
+{
+ /* satisfy -Wall */
+ THRIFT_UNUSED_VAR (protocol);
+ THRIFT_UNUSED_VAR (error);
+ return 0;
+}
+
+gint32
+thrift_binary_protocol_write_struct_begin (ThriftProtocol *protocol,
+ const gchar *name,
+ GError **error)
+{
+ /* satisfy -Wall */
+ THRIFT_UNUSED_VAR (protocol);
+ THRIFT_UNUSED_VAR (name);
+ THRIFT_UNUSED_VAR (error);
+ return 0;
+}
+
+gint32
+thrift_binary_protocol_write_struct_end (ThriftProtocol *protocol,
+ GError **error)
+{
+ /* satisfy -Wall */
+ THRIFT_UNUSED_VAR (protocol);
+ THRIFT_UNUSED_VAR (error);
+ return 0;
+}
+
+gint32
+thrift_binary_protocol_write_field_begin (ThriftProtocol *protocol,
+ const gchar *name,
+ const ThriftType field_type,
+ const gint16 field_id,
+ GError **error)
+{
+ THRIFT_UNUSED_VAR (name);
+ g_return_val_if_fail (THRIFT_IS_BINARY_PROTOCOL (protocol), -1);
+
+ gint32 ret;
+ gint32 xfer = 0;
+
+ if ((ret = thrift_protocol_write_byte (protocol, (gint8) field_type,
+ error)) < 0)
+ {
+ return -1;
+ }
+ xfer += ret;
+ if ((ret = thrift_protocol_write_i16 (protocol, field_id, error)) < 0)
+ {
+ return -1;
+ }
+ xfer += ret;
+ return xfer;
+}
+
+gint32
+thrift_binary_protocol_write_field_end (ThriftProtocol *protocol,
+ GError **error)
+{
+ /* satisfy -Wall */
+ THRIFT_UNUSED_VAR (protocol);
+ THRIFT_UNUSED_VAR (error);
+ return 0;
+}
+
+gint32
+thrift_binary_protocol_write_field_stop (ThriftProtocol *protocol,
+ GError **error)
+{
+ g_return_val_if_fail (THRIFT_IS_BINARY_PROTOCOL (protocol), -1);
+ return thrift_protocol_write_byte (protocol, (gint8) T_STOP, error);
+}
+
+gint32
+thrift_binary_protocol_write_map_begin (ThriftProtocol *protocol,
+ const ThriftType key_type,
+ const ThriftType value_type,
+ const guint32 size,
+ GError **error)
+{
+ g_return_val_if_fail (THRIFT_IS_BINARY_PROTOCOL (protocol), -1);
+
+ gint32 ret;
+ gint32 xfer = 0;
+
+ if ((ret = thrift_protocol_write_byte (protocol, (gint8) key_type,
+ error)) < 0)
+ {
+ return -1;
+ }
+ xfer += ret;
+ if ((ret = thrift_protocol_write_byte (protocol, (gint8) value_type,
+ error)) < 0)
+ {
+ return -1;
+ }
+ xfer += ret;
+ if ((ret = thrift_protocol_write_i32 (protocol, (gint32) size, error)) < 0)
+ {
+ return -1;
+ }
+ xfer += ret;
+ return xfer;
+}
+
+gint32
+thrift_binary_protocol_write_map_end (ThriftProtocol *protocol,
+ GError **error)
+{
+ THRIFT_UNUSED_VAR (protocol);
+ THRIFT_UNUSED_VAR (error);
+ return 0;
+}
+
+gint32
+thrift_binary_protocol_write_list_begin (ThriftProtocol *protocol,
+ const ThriftType element_type,
+ const guint32 size,
+ GError **error)
+{
+ g_return_val_if_fail (THRIFT_IS_BINARY_PROTOCOL (protocol), -1);
+
+ gint32 ret;
+ gint32 xfer = 0;
+
+ if ((ret = thrift_protocol_write_byte (protocol, (gint8) element_type,
+ error)) < 0)
+ {
+ return -1;
+ }
+ xfer += ret;
+
+ if ((ret = thrift_protocol_write_i32 (protocol, (gint32) size, error)) < 0)
+ {
+ return -1;
+ }
+ xfer += ret;
+
+ return xfer;
+}
+
+gint32
+thrift_binary_protocol_write_list_end (ThriftProtocol *protocol,
+ GError **error)
+{
+ THRIFT_UNUSED_VAR (protocol);
+ THRIFT_UNUSED_VAR (error);
+ return 0;
+}
+
+gint32
+thrift_binary_protocol_write_set_begin (ThriftProtocol *protocol,
+ const ThriftType element_type,
+ const guint32 size,
+ GError **error)
+{
+ g_return_val_if_fail (THRIFT_IS_BINARY_PROTOCOL (protocol), -1);
+
+ return thrift_protocol_write_list_begin (protocol, element_type,
+ size, error);
+}
+
+gint32
+thrift_binary_protocol_write_set_end (ThriftProtocol *protocol, GError **error)
+{
+ THRIFT_UNUSED_VAR (protocol);
+ THRIFT_UNUSED_VAR (error);
+ return 0;
+}
+
+gint32
+thrift_binary_protocol_write_bool (ThriftProtocol *protocol,
+ const gboolean value, GError **error)
+{
+ g_return_val_if_fail (THRIFT_IS_BINARY_PROTOCOL (protocol), -1);
+ guint8 tmp = value ? 1 : 0;
+ return thrift_protocol_write_byte (protocol, tmp, error);
+}
+
+gint32
+thrift_binary_protocol_write_byte (ThriftProtocol *protocol, const gint8 value,
+ GError **error)
+{
+ g_return_val_if_fail (THRIFT_IS_BINARY_PROTOCOL (protocol), -1);
+
+ if (thrift_transport_write (protocol->transport,
+ (const gpointer) &value, 1, error))
+ {
+ return 1;
+ } else {
+ return -1;
+ }
+}
+
+gint32
+thrift_binary_protocol_write_i16 (ThriftProtocol *protocol, const gint16 value,
+ GError **error)
+{
+ g_return_val_if_fail (THRIFT_IS_BINARY_PROTOCOL (protocol), -1);
+
+ gint16 net = g_htons (value);
+ if (thrift_transport_write (protocol->transport,
+ (const gpointer) &net, 2, error))
+ {
+ return 2;
+ } else {
+ return -1;
+ }
+}
+
+gint32
+thrift_binary_protocol_write_i32 (ThriftProtocol *protocol, const gint32 value,
+ GError **error)
+{
+ g_return_val_if_fail (THRIFT_IS_BINARY_PROTOCOL (protocol), -1);
+
+ gint32 net = g_htonl (value);
+ if (thrift_transport_write (protocol->transport,
+ (const gpointer) &net, 4, error))
+ {
+ return 4;
+ } else {
+ return -1;
+ }
+}
+
+gint32
+thrift_binary_protocol_write_i64 (ThriftProtocol *protocol, const gint64 value,
+ GError **error)
+{
+ g_return_val_if_fail (THRIFT_IS_BINARY_PROTOCOL (protocol), -1);
+
+ gint64 net = GUINT64_TO_BE (value);
+ if (thrift_transport_write (protocol->transport,
+ (const gpointer) &net, 8, error))
+ {
+ return 8;
+ } else {
+ return -1;
+ }
+}
+
+gint32
+thrift_binary_protocol_write_double (ThriftProtocol *protocol,
+ const gdouble value, GError **error)
+{
+ g_return_val_if_fail (THRIFT_IS_BINARY_PROTOCOL (protocol), -1);
+
+ guint64 bits = GUINT64_FROM_BE (thrift_bitwise_cast_guint64 (value));
+ if (thrift_transport_write (protocol->transport,
+ (const gpointer) &bits, 8, error))
+ {
+ return 8;
+ } else {
+ return -1;
+ }
+}
+
+gint32
+thrift_binary_protocol_write_string (ThriftProtocol *protocol,
+ const gchar *str, GError **error)
+{
+ g_return_val_if_fail (THRIFT_IS_BINARY_PROTOCOL (protocol), -1);
+
+ guint32 len = str != NULL ? strlen (str) : 0;
+ /* write the string length + 1 which includes the null terminator */
+ return thrift_protocol_write_binary (protocol, (const gpointer) str,
+ len, error);
+}
+
+gint32
+thrift_binary_protocol_write_binary (ThriftProtocol *protocol,
+ const gpointer buf,
+ const guint32 len, GError **error)
+{
+ g_return_val_if_fail (THRIFT_IS_BINARY_PROTOCOL (protocol), -1);
+ gint32 ret;
+ gint32 xfer = 0;
+
+ if ((ret = thrift_protocol_write_i32 (protocol, len, error)) < 0)
+ {
+ return -1;
+ }
+ xfer += ret;
+
+ if (len > 0)
+ {
+ if (thrift_transport_write (protocol->transport,
+ (const gpointer) buf, len, error) == FALSE)
+ {
+ return -1;
+ }
+ xfer += len;
+ }
+
+ return xfer;
+}
+
+gint32
+thrift_binary_protocol_read_message_begin (ThriftProtocol *protocol,
+ gchar **name,
+ ThriftMessageType *message_type,
+ gint32 *seqid, GError **error)
+{
+ g_return_val_if_fail (THRIFT_IS_BINARY_PROTOCOL (protocol), -1);
+
+ gint32 ret;
+ gint32 xfer = 0;
+ gint32 sz;
+
+ if ((ret = thrift_protocol_read_i32 (protocol, &sz, error)) < 0)
+ {
+ return -1;
+ }
+ xfer += ret;
+
+ if (sz < 0)
+ {
+ /* check for version */
+ guint32 version = sz & THRIFT_BINARY_PROTOCOL_VERSION_MASK;
+ if (version != THRIFT_BINARY_PROTOCOL_VERSION_1)
+ {
+ g_set_error (error, THRIFT_PROTOCOL_ERROR,
+ THRIFT_PROTOCOL_ERROR_BAD_VERSION,
+ "expected version %d, got %d",
+ THRIFT_BINARY_PROTOCOL_VERSION_1, version);
+ return -1;
+ }
+
+ *message_type = (ThriftMessageType) (sz & 0x000000ff);
+
+ if ((ret = thrift_protocol_read_string (protocol, name, error)) < 0)
+ {
+ return -1;
+ }
+ xfer += ret;
+
+ if ((ret = thrift_protocol_read_i32 (protocol, seqid, error)) < 0)
+ {
+ return -1;
+ }
+ xfer += ret;
+ }
+ return xfer;
+}
+
+gint32
+thrift_binary_protocol_read_message_end (ThriftProtocol *protocol,
+ GError **error)
+{
+ THRIFT_UNUSED_VAR (protocol);
+ THRIFT_UNUSED_VAR (error);
+ return 0;
+}
+
+gint32
+thrift_binary_protocol_read_struct_begin (ThriftProtocol *protocol,
+ gchar **name,
+ GError **error)
+{
+ THRIFT_UNUSED_VAR (protocol);
+ THRIFT_UNUSED_VAR (error);
+ *name = NULL;
+ return 0;
+}
+
+gint32
+thrift_binary_protocol_read_struct_end (ThriftProtocol *protocol,
+ GError **error)
+{
+ THRIFT_UNUSED_VAR (protocol);
+ THRIFT_UNUSED_VAR (error);
+ return 0;
+}
+
+gint32
+thrift_binary_protocol_read_field_begin (ThriftProtocol *protocol,
+ gchar **name,
+ ThriftType *field_type,
+ gint16 *field_id,
+ GError **error)
+{
+ THRIFT_UNUSED_VAR (name);
+ g_return_val_if_fail (THRIFT_IS_BINARY_PROTOCOL (protocol), -1);
+
+ gint32 ret;
+ gint32 xfer = 0;
+ gint8 type;
+
+ if ((ret = thrift_protocol_read_byte (protocol, &type, error)) < 0)
+ {
+ return -1;
+ }
+ xfer += ret;
+ *field_type = (ThriftType) type;
+ if (*field_type == T_STOP)
+ {
+ *field_id = 0;
+ return xfer;
+ }
+ if ((ret = thrift_protocol_read_i16 (protocol, field_id, error)) < 0)
+ {
+ return -1;
+ }
+ xfer += ret;
+ return xfer;
+}
+
+gint32
+thrift_binary_protocol_read_field_end (ThriftProtocol *protocol,
+ GError **error)
+{
+ THRIFT_UNUSED_VAR (protocol);
+ THRIFT_UNUSED_VAR (error);
+ return 0;
+}
+
+gint32
+thrift_binary_protocol_read_map_begin (ThriftProtocol *protocol,
+ ThriftType *key_type,
+ ThriftType *value_type,
+ guint32 *size,
+ GError **error)
+{
+ g_return_val_if_fail (THRIFT_IS_BINARY_PROTOCOL (protocol), -1);
+
+ gint32 ret;
+ gint32 xfer = 0;
+ gint8 k, v;
+ gint32 sizei;
+
+ if ((ret = thrift_protocol_read_byte (protocol, &k, error)) < 0)
+ {
+ return -1;
+ }
+ xfer += ret;
+ *key_type = (ThriftType) k;
+
+ if ((ret = thrift_protocol_read_byte (protocol, &v, error)) < 0)
+ {
+ return -1;
+ }
+ xfer += ret;
+ *value_type = (ThriftType) v;
+
+ if ((ret = thrift_protocol_read_i32 (protocol, &sizei, error)) <0)
+ {
+ return -1;
+ }
+ xfer += ret;
+
+ if (sizei < 0)
+ {
+ g_set_error (error, THRIFT_PROTOCOL_ERROR,
+ THRIFT_PROTOCOL_ERROR_NEGATIVE_SIZE,
+ "got negative size of %d", sizei);
+ return -1;
+ }
+
+ *size = (guint32) sizei;
+ return xfer;
+}
+
+gint32
+thrift_binary_protocol_read_map_end (ThriftProtocol *protocol,
+ GError **error)
+{
+ THRIFT_UNUSED_VAR (protocol);
+ THRIFT_UNUSED_VAR (error);
+ return 0;
+}
+
+gint32
+thrift_binary_protocol_read_list_begin (ThriftProtocol *protocol,
+ ThriftType *element_type,
+ guint32 *size, GError **error)
+{
+ g_return_val_if_fail (THRIFT_IS_BINARY_PROTOCOL (protocol), -1);
+
+ gint32 ret;
+ gint32 xfer = 0;
+ gint8 e;
+ gint32 sizei;
+
+ if ((ret = thrift_protocol_read_byte (protocol, &e, error)) < 0)
+ {
+ return -1;
+ }
+ xfer += ret;
+ *element_type = (ThriftType) e;
+
+ if ((ret = thrift_protocol_read_i32 (protocol, &sizei, error)) < 0)
+ {
+ return -1;
+ }
+ xfer += ret;
+
+ if (sizei < 0)
+ {
+ g_set_error (error, THRIFT_PROTOCOL_ERROR,
+ THRIFT_PROTOCOL_ERROR_NEGATIVE_SIZE,
+ "got negative size of %d", sizei);
+ return -1;
+ }
+
+ *size = (guint32) sizei;
+ return xfer;
+}
+
+gint32
+thrift_binary_protocol_read_list_end (ThriftProtocol *protocol,
+ GError **error)
+{
+ THRIFT_UNUSED_VAR (protocol);
+ THRIFT_UNUSED_VAR (error);
+ return 0;
+}
+
+gint32
+thrift_binary_protocol_read_set_begin (ThriftProtocol *protocol,
+ ThriftType *element_type,
+ guint32 *size, GError **error)
+{
+ g_return_val_if_fail (THRIFT_IS_BINARY_PROTOCOL (protocol), -1);
+
+ return thrift_protocol_read_list_begin (protocol, element_type, size, error);
+}
+
+gint32
+thrift_binary_protocol_read_set_end (ThriftProtocol *protocol,
+ GError **error)
+{
+ THRIFT_UNUSED_VAR (protocol);
+ THRIFT_UNUSED_VAR (error);
+ return 0;
+}
+
+gint32
+thrift_binary_protocol_read_bool (ThriftProtocol *protocol, gboolean *value,
+ GError **error)
+{
+ g_return_val_if_fail (THRIFT_IS_BINARY_PROTOCOL (protocol), -1);
+ gint32 ret;
+ gpointer b[1];
+
+ if ((ret =
+ thrift_transport_read (protocol->transport,
+ b, 1, error)) < 0)
+ {
+ return -1;
+ }
+ *value = *(gint8 *) b != 0;
+ return ret;
+}
+
+gint32
+thrift_binary_protocol_read_byte (ThriftProtocol *protocol, gint8 *value,
+ GError **error)
+{
+ g_return_val_if_fail (THRIFT_IS_BINARY_PROTOCOL (protocol), -1);
+ gint32 ret;
+ gpointer b[1];
+
+ if ((ret =
+ thrift_transport_read (protocol->transport,
+ b, 1, error)) < 0)
+ {
+ return -1;
+ }
+ *value = *(gint8 *) b;
+ return ret;
+}
+
+gint32
+thrift_binary_protocol_read_i16 (ThriftProtocol *protocol, gint16 *value,
+ GError **error)
+{
+ g_return_val_if_fail (THRIFT_IS_BINARY_PROTOCOL (protocol), -1);
+ gint32 ret;
+ gpointer b[2];
+
+ if ((ret =
+ thrift_transport_read (protocol->transport,
+ b, 2, error)) < 0)
+ {
+ return -1;
+ }
+ *value = *(gint16 *) b;
+ *value = g_ntohs (*value);
+ return ret;
+}
+
+gint32
+thrift_binary_protocol_read_i32 (ThriftProtocol *protocol, gint32 *value,
+ GError **error)
+{
+ g_return_val_if_fail (THRIFT_IS_BINARY_PROTOCOL (protocol), -1);
+ gint32 ret;
+ gpointer b[4];
+
+ if ((ret =
+ thrift_transport_read (protocol->transport,
+ b, 4, error)) < 0)
+ {
+ return -1;
+ }
+ *value = *(gint32 *) b;
+ *value = g_ntohl (*value);
+ return ret;
+}
+
+gint32
+thrift_binary_protocol_read_i64 (ThriftProtocol *protocol, gint64 *value,
+ GError **error)
+{
+ g_return_val_if_fail (THRIFT_IS_BINARY_PROTOCOL (protocol), -1);
+ gint32 ret;
+ gpointer b[8];
+
+ if ((ret =
+ thrift_transport_read (protocol->transport,
+ b, 8, error)) < 0)
+ {
+ return -1;
+ }
+ *value = *(gint64 *) b;
+ *value = GUINT64_FROM_BE (*value);
+ return ret;
+}
+
+gint32
+thrift_binary_protocol_read_double (ThriftProtocol *protocol,
+ gdouble *value, GError **error)
+{
+ g_return_val_if_fail (THRIFT_IS_BINARY_PROTOCOL (protocol), -1);
+ gint32 ret;
+ gpointer b[8];
+
+ if ((ret =
+ thrift_transport_read (protocol->transport,
+ b, 8, error)) < 0)
+ {
+ return -1;
+ }
+ guint64 bits = *(guint64 *) b;
+ bits = GUINT64_FROM_BE (bits);
+ *value = thrift_bitwise_cast_gdouble (bits);
+ return ret;
+}
+
+gint32
+thrift_binary_protocol_read_string (ThriftProtocol *protocol,
+ gchar **str, GError **error)
+{
+ g_return_val_if_fail (THRIFT_IS_BINARY_PROTOCOL (protocol), -1);
+ guint32 len;
+ gint32 ret;
+ gint32 xfer = 0;
+ gint32 read_len = 0;
+
+ /* read the length into read_len */
+ if ((ret =
+ thrift_protocol_read_i32 (protocol, &read_len, error)) < 0)
+ {
+ return -1;
+ }
+ xfer += ret;
+
+ if (read_len > 0)
+ {
+ /* allocate the memory for the string */
+ len = (guint32) read_len + 1; // space for null terminator
+ *str = g_new0 (gchar, len);
+ if ((ret =
+ thrift_transport_read (protocol->transport,
+ *str, read_len, error)) < 0)
+ {
+ g_free (*str);
+ *str = NULL;
+ len = 0;
+ return -1;
+ }
+ xfer += ret;
+ } else {
+ *str = NULL;
+ }
+
+ return xfer;
+}
+
+gint32
+thrift_binary_protocol_read_binary (ThriftProtocol *protocol,
+ gpointer *buf, guint32 *len,
+ GError **error)
+{
+ g_return_val_if_fail (THRIFT_IS_BINARY_PROTOCOL (protocol), -1);
+ gint32 ret;
+ gint32 xfer = 0;
+ gint32 read_len = 0;
+
+ /* read the length into read_len */
+ if ((ret =
+ thrift_protocol_read_i32 (protocol, &read_len, error)) < 0)
+ {
+ return -1;
+ }
+ xfer += ret;
+
+ if (read_len > 0)
+ {
+ /* allocate the memory as an array of unsigned char for binary data */
+ *len = (guint32) read_len;
+ *buf = g_new (guchar, *len);
+ if ((ret =
+ thrift_transport_read (protocol->transport,
+ *buf, *len, error)) < 0)
+ {
+ g_free (*buf);
+ *buf = NULL;
+ *len = 0;
+ return -1;
+ }
+ xfer += ret;
+ } else {
+ *buf = NULL;
+ }
+
+ return xfer;
+}
+
+
Added: incubator/thrift/trunk/lib/c_glib/src/protocol/thrift_binary_protocol.h
URL: http://svn.apache.org/viewvc/incubator/thrift/trunk/lib/c_glib/src/protocol/thrift_binary_protocol.h?rev=1027933&view=auto
==============================================================================
--- incubator/thrift/trunk/lib/c_glib/src/protocol/thrift_binary_protocol.h (added)
+++ incubator/thrift/trunk/lib/c_glib/src/protocol/thrift_binary_protocol.h Wed Oct 27 12:30:11 2010
@@ -0,0 +1,55 @@
+#ifndef _THRIFT_BINARY_PROTOCOL_H
+#define _THRIFT_BINARY_PROTOCOL_H
+
+#include <glib-object.h>
+
+#include "protocol/thrift_protocol.h"
+#include "transport/thrift_transport.h"
+
+/*! \file thrift_binary_protocol.h
+ * \brief Binary protocol implementation of a Thrift protocol. Implements the
+ * ThriftProtocol interface.
+ */
+
+/* type macros */
+#define THRIFT_TYPE_BINARY_PROTOCOL (thrift_binary_protocol_get_type ())
+#define THRIFT_BINARY_PROTOCOL(obj) (G_TYPE_CHECK_INSTANCE_CAST ((obj), \
+ THRIFT_TYPE_BINARY_PROTOCOL, \
+ ThriftBinaryProtocol))
+#define THRIFT_IS_BINARY_PROTOCOL(obj) (G_TYPE_CHECK_INSTANCE_TYPE ((obj), \
+ THRIFT_TYPE_BINARY_PROTOCOL))
+#define THRIFT_BINARY_PROTOCOL_CLASS(c) (G_TYPE_CHECK_CLASS_CAST ((c), \
+ THRIFT_TYPE_BINARY_PROTOCOL, \
+ ThriftBinaryProtocolClass))
+#define THRIFT_IS_BINARY_PROTOCOL_CLASS(c) (G_TYPE_CHECK_CLASS_TYPE ((c), \
+ THRIFT_TYPE_BINARY_PROTOCOL))
+#define THRIFT_BINARY_PROTOCOL_GET_CLASS(obj) \
+ (G_TYPE_INSTANCE_GET_CLASS ((obj), THRIFT_TYPE_BINARY_PROTOCOL, \
+ ThriftBinaryProtocolClass))
+
+/* version numbers */
+#define THRIFT_BINARY_PROTOCOL_VERSION_1 0x80010000
+#define THRIFT_BINARY_PROTOCOL_VERSION_MASK 0xffff0000
+
+/*!
+ * Thrift Binary Protocol instance.
+ */
+struct _ThriftBinaryProtocol
+{
+ ThriftProtocol parent;
+};
+typedef struct _ThriftBinaryProtocol ThriftBinaryProtocol;
+
+/*!
+ * Thrift Binary Protocol class.
+ */
+struct _ThriftBinaryProtocolClass
+{
+ ThriftProtocolClass parent;
+};
+typedef struct _ThriftBinaryProtocolClass ThriftBinaryProtocolClass;
+
+/* used by THRIFT_TYPE_BINARY_PROTOCOL */
+GType thrift_binary_protocol_get_type (void);
+
+#endif /* _THRIFT_BINARY_PROTOCOL_H */
Added: incubator/thrift/trunk/lib/c_glib/src/protocol/thrift_binary_protocol_factory.c
URL: http://svn.apache.org/viewvc/incubator/thrift/trunk/lib/c_glib/src/protocol/thrift_binary_protocol_factory.c?rev=1027933&view=auto
==============================================================================
--- incubator/thrift/trunk/lib/c_glib/src/protocol/thrift_binary_protocol_factory.c (added)
+++ incubator/thrift/trunk/lib/c_glib/src/protocol/thrift_binary_protocol_factory.c Wed Oct 27 12:30:11 2010
@@ -0,0 +1,58 @@
+
+#include "thrift.h"
+#include "protocol/thrift_binary_protocol.h"
+#include "protocol/thrift_binary_protocol_factory.h"
+
+/* forward declarations */
+static void thrift_binary_protocol_factory_class_init (ThriftProtocolFactoryClass *cls);
+
+ThriftProtocol *thrift_binary_protocol_factory_get_protocol (ThriftProtocolFactory *factory, ThriftTransport *transport);
+
+GType
+thrift_binary_protocol_factory_get_type (void)
+{
+ static GType type = 0;
+
+ if (type == 0)
+ {
+ static const GTypeInfo info =
+ {
+ sizeof (ThriftBinaryProtocolFactoryClass),
+ NULL, /* base_init */
+ NULL, /* base_finalize */
+ (GClassInitFunc) thrift_binary_protocol_factory_class_init,
+ NULL, /* class_finalize */
+ NULL, /* class_data */
+ sizeof (ThriftBinaryProtocolFactory),
+ 0, /* n_preallocs */
+ NULL, /* instance_init */
+ NULL, /* value_table */
+ };
+
+ type = g_type_register_static (THRIFT_TYPE_PROTOCOL_FACTORY,
+ "ThriftBinaryProtocolFactoryType",
+ &info, 0);
+ }
+
+ return type;
+}
+
+static void
+thrift_binary_protocol_factory_class_init (ThriftProtocolFactoryClass *cls)
+{
+ cls->get_protocol = thrift_binary_protocol_factory_get_protocol;
+}
+
+ThriftProtocol *
+thrift_binary_protocol_factory_get_protocol (ThriftProtocolFactory *factory,
+ ThriftTransport *transport)
+{
+ THRIFT_UNUSED_VAR (factory);
+
+ ThriftBinaryProtocol *tb = g_object_new (THRIFT_TYPE_BINARY_PROTOCOL,
+ "transport", transport, NULL);
+
+ return THRIFT_PROTOCOL (tb);
+}
+
+
Added: incubator/thrift/trunk/lib/c_glib/src/protocol/thrift_binary_protocol_factory.h
URL: http://svn.apache.org/viewvc/incubator/thrift/trunk/lib/c_glib/src/protocol/thrift_binary_protocol_factory.h?rev=1027933&view=auto
==============================================================================
--- incubator/thrift/trunk/lib/c_glib/src/protocol/thrift_binary_protocol_factory.h (added)
+++ incubator/thrift/trunk/lib/c_glib/src/protocol/thrift_binary_protocol_factory.h Wed Oct 27 12:30:11 2010
@@ -0,0 +1,46 @@
+#ifndef _THRIFT_BINARY_PROTOCOL_FACTORY_H
+#define _THRIFT_BINARY_PROTOCOL_FACTORY_H
+
+#include <glib-object.h>
+
+#include "protocol/thrift_protocol_factory.h"
+
+/* type macros */
+#define THRIFT_TYPE_BINARY_PROTOCOL_FACTORY \
+ (thrift_binary_protocol_factory_get_type ())
+#define THRIFT_BINARY_PROTOCOL_FACTORY(obj) \
+ (G_TYPE_CHECK_INSTANCE_CAST ((obj), \
+ THRIFT_TYPE_BINARY_PROTOCOL_FACTORY, \
+ ThriftBinaryProtocolFactory))
+#define THRIFT_IS_BINARY_PROTOCOL_FACTORY(obj) \
+ (G_TYPE_CHECK_INSTANCE_TYPE ((obj), \
+ THRIFT_TYPE_BINARY_PROTOCOL_FACTORY))
+#define THRIFT_BINARY_PROTOCOL_FACTORY_CLASS(c) \
+ (G_TYPE_CHECK_CLASS_CAST ((c), \
+ THRIFT_TYPE_BINARY_PROTOCOL_FACTORY, \
+ ThriftBinaryProtocolFactoryClass))
+#define THRIFT_IS_BINARY_PROTOCOL_FACTORY_CLASS(c) \
+ (G_TYPE_CHECK_CLASS_TYPE ((c), \
+ THRIFT_TYPE_BINARY_PROTOCOL_FACTORY))
+#define THRIFT_BINARY_PROTOCOL_FACTORY_GET_CLASS(obj) \
+ (G_TYPE_INSTANCE_GET_CLASS ((obj), \
+ THRIFT_TYPE_BINARY_PROTOCOL_FACTORY, \
+ ThriftBinaryProtocolFactoryClass))
+
+struct _ThriftBinaryProtocolFactory
+{
+ ThriftProtocolFactory parent;
+};
+typedef struct _ThriftBinaryProtocolFactory ThriftBinaryProtocolFactory;
+
+struct _ThriftBinaryProtocolFactoryClass
+{
+ ThriftProtocolFactoryClass parent;
+};
+typedef struct _ThriftBinaryProtocolFactoryClass
+ ThriftBinaryProtocolFactoryClass;
+
+/* used by THRIFT_TYPE_BINARY_PROTOCOL_FACTORY */
+GType thrift_binary_protocol_factory_get_type (void);
+
+#endif /* _THRIFT_BINARY_PROTOCOL_FACTORY_H */
Added: incubator/thrift/trunk/lib/c_glib/src/protocol/thrift_protocol.c
URL: http://svn.apache.org/viewvc/incubator/thrift/trunk/lib/c_glib/src/protocol/thrift_protocol.c?rev=1027933&view=auto
==============================================================================
--- incubator/thrift/trunk/lib/c_glib/src/protocol/thrift_protocol.c (added)
+++ incubator/thrift/trunk/lib/c_glib/src/protocol/thrift_protocol.c Wed Oct 27 12:30:11 2010
@@ -0,0 +1,604 @@
+#include "thrift.h"
+#include "protocol/thrift_protocol.h"
+#include "transport/thrift_transport.h"
+
+/* define the GError domain string */
+#define THRIFT_PROTOCOL_ERROR_DOMAIN "thrift-protocol-error-quark"
+
+/* object properties */
+enum _ThriftProtocolProperties
+{
+ PROP_0,
+ PROP_THRIFT_PROTOCOL_TRANSPORT
+};
+
+/* forward declarations */
+static void thrift_protocol_instance_init (ThriftProtocol *protocol);
+static void thrift_protocol_class_init (ThriftProtocolClass *cls);
+void thrift_protocol_get_property (GObject *object, guint property_id,
+ GValue *value, GParamSpec *pspec);
+void thrift_protocol_set_property (GObject *object, guint property_id,
+ const GValue *value, GParamSpec *pspec);
+
+/* define ThriftProtocolInterface's type */
+GType
+thrift_protocol_get_type (void)
+{
+ static GType type = 0;
+
+ if (type == 0)
+ {
+ static const GTypeInfo info = {
+ sizeof (ThriftProtocolClass),
+ NULL, /* base_init */
+ NULL, /* base_finalize */
+ (GClassInitFunc) thrift_protocol_class_init,
+ NULL, /* class_finalize */
+ NULL, /* class_data */
+ sizeof (ThriftProtocol),
+ 0, /* n_preallocs */
+ (GInstanceInitFunc) thrift_protocol_instance_init,
+ NULL, /* value_table */
+ };
+
+ type = g_type_register_static (G_TYPE_OBJECT, "ThriftProtocol",
+ &info, G_TYPE_FLAG_ABSTRACT);
+ }
+
+ return type;
+}
+
+static void
+thrift_protocol_instance_init (ThriftProtocol *protocol)
+{
+ protocol->transport = NULL;
+}
+
+static void
+thrift_protocol_class_init (ThriftProtocolClass *cls)
+{
+ GObjectClass *gobject_class = G_OBJECT_CLASS (cls);
+
+ gobject_class->get_property = thrift_protocol_get_property;
+ gobject_class->set_property = thrift_protocol_set_property;
+
+ g_object_class_install_property (gobject_class,
+ PROP_THRIFT_PROTOCOL_TRANSPORT,
+ g_param_spec_object ("transport", "Transport", "Thrift Transport",
+ THRIFT_TYPE_TRANSPORT,
+ G_PARAM_READWRITE | G_PARAM_CONSTRUCT_ONLY));
+
+ cls->write_message_begin = thrift_protocol_write_message_begin;
+ cls->write_message_end = thrift_protocol_write_message_end;
+ cls->write_struct_begin = thrift_protocol_write_struct_begin;
+ cls->write_struct_end = thrift_protocol_write_struct_end;
+ cls->write_field_begin = thrift_protocol_write_field_begin;
+ cls->write_field_end = thrift_protocol_write_field_end;
+ cls->write_field_stop = thrift_protocol_write_field_stop;
+ cls->write_map_begin = thrift_protocol_write_map_begin;
+ cls->write_map_end = thrift_protocol_write_map_end;
+ cls->write_list_begin = thrift_protocol_write_list_begin;
+ cls->write_list_end = thrift_protocol_write_list_end;
+ cls->write_set_begin = thrift_protocol_write_set_begin;
+ cls->write_set_end = thrift_protocol_write_set_end;
+ cls->write_bool = thrift_protocol_write_bool;
+ cls->write_byte = thrift_protocol_write_byte;
+ cls->write_i16 = thrift_protocol_write_i16;
+ cls->write_i32 = thrift_protocol_write_i32;
+ cls->write_i64 = thrift_protocol_write_i64;
+ cls->write_double = thrift_protocol_write_double;
+ cls->write_string = thrift_protocol_write_string;
+ cls->write_binary = thrift_protocol_write_binary;
+ cls->read_message_begin = thrift_protocol_read_message_begin;
+ cls->read_message_end = thrift_protocol_read_message_end;
+ cls->read_struct_begin = thrift_protocol_read_struct_begin;
+ cls->read_struct_end = thrift_protocol_read_struct_end;
+ cls->read_field_begin = thrift_protocol_read_field_begin;
+ cls->read_field_end = thrift_protocol_read_field_end;
+ cls->read_map_begin = thrift_protocol_read_map_begin;
+ cls->read_map_end = thrift_protocol_read_map_end;
+ cls->read_list_begin = thrift_protocol_read_list_begin;
+ cls->read_set_begin = thrift_protocol_read_set_begin;
+ cls->read_set_end = thrift_protocol_read_set_end;
+ cls->read_bool = thrift_protocol_read_bool;
+ cls->read_byte = thrift_protocol_read_byte;
+ cls->read_i16 = thrift_protocol_read_i16;
+ cls->read_i32 = thrift_protocol_read_i32;
+ cls->read_i64 = thrift_protocol_read_i64;
+ cls->read_double = thrift_protocol_read_double;
+ cls->read_string = thrift_protocol_read_string;
+ cls->read_binary = thrift_protocol_read_binary;
+}
+
+void
+thrift_protocol_get_property (GObject *object, guint property_id,
+ GValue *value, GParamSpec *pspec)
+{
+ ThriftProtocol *protocol = THRIFT_PROTOCOL (object);
+
+ THRIFT_UNUSED_VAR (pspec);
+
+ switch (property_id)
+ {
+ case PROP_THRIFT_PROTOCOL_TRANSPORT:
+ g_value_set_object (value, protocol->transport);
+ break;
+ }
+}
+
+void
+thrift_protocol_set_property (GObject *object, guint property_id,
+ const GValue *value, GParamSpec *pspec)
+{
+
+ ThriftProtocol *protocol = THRIFT_PROTOCOL (object);
+
+ THRIFT_UNUSED_VAR (pspec);
+
+ switch (property_id)
+ {
+ case PROP_THRIFT_PROTOCOL_TRANSPORT:
+ protocol->transport = g_value_get_object (value);
+ break;
+ }
+}
+
+
+gint32
+thrift_protocol_write_message_begin (ThriftProtocol *protocol,
+ const gchar *name,
+ const ThriftMessageType message_type,
+ const gint32 seqid, GError **error)
+{
+ return THRIFT_PROTOCOL_GET_CLASS (protocol)->write_message_begin
+ (protocol, name,
+ message_type, seqid,
+ error);
+}
+
+gint32
+thrift_protocol_write_message_end (ThriftProtocol *protocol, GError **error)
+{
+ return THRIFT_PROTOCOL_GET_CLASS (protocol)->write_message_end (protocol,
+ error);
+}
+
+gint32
+thrift_protocol_write_struct_begin (ThriftProtocol *protocol, const gchar *name,
+ GError **error)
+{
+ return THRIFT_PROTOCOL_GET_CLASS (protocol)->write_struct_begin (protocol,
+ name, error);
+}
+
+gint32
+thrift_protocol_write_struct_end (ThriftProtocol *protocol, GError **error)
+{
+ return THRIFT_PROTOCOL_GET_CLASS (protocol)->write_struct_end (protocol,
+ error);
+}
+
+gint32
+thrift_protocol_write_field_begin (ThriftProtocol *protocol,
+ const gchar *name,
+ const ThriftType field_type,
+ const gint16 field_id,
+ GError **error)
+{
+ return THRIFT_PROTOCOL_GET_CLASS (protocol)->write_field_begin (protocol,
+ name, field_type,
+ field_id, error);
+}
+
+gint32
+thrift_protocol_write_field_end (ThriftProtocol *protocol, GError **error)
+{
+ return THRIFT_PROTOCOL_GET_CLASS (protocol)->write_field_end (protocol,
+ error);
+}
+
+gint32
+thrift_protocol_write_field_stop (ThriftProtocol *protocol, GError **error)
+{
+ return THRIFT_PROTOCOL_GET_CLASS (protocol)->write_field_stop (protocol,
+ error);
+}
+
+gint32
+thrift_protocol_write_map_begin (ThriftProtocol *protocol,
+ const ThriftType key_type,
+ const ThriftType value_type,
+ const guint32 size, GError **error)
+{
+ return THRIFT_PROTOCOL_GET_CLASS (protocol)->write_map_begin (protocol,
+ key_type, value_type,
+ size, error);
+}
+
+gint32
+thrift_protocol_write_map_end (ThriftProtocol *protocol, GError **error)
+{
+ return THRIFT_PROTOCOL_GET_CLASS (protocol)->write_map_end (protocol,
+ error);
+}
+
+gint32
+thrift_protocol_write_list_begin (ThriftProtocol *protocol,
+ const ThriftType element_type,
+ const guint32 size, GError **error)
+{
+ return THRIFT_PROTOCOL_GET_CLASS (protocol)->write_list_begin (protocol,
+ element_type, size,
+ error);
+}
+
+gint32
+thrift_protocol_write_list_end (ThriftProtocol *protocol, GError **error)
+{
+ return THRIFT_PROTOCOL_GET_CLASS (protocol)->write_list_end (protocol,
+ error);
+}
+
+gint32
+thrift_protocol_write_set_begin (ThriftProtocol *protocol,
+ const ThriftType element_type,
+ const guint32 size, GError **error)
+{
+ return THRIFT_PROTOCOL_GET_CLASS (protocol)->write_set_begin (protocol,
+ element_type, size,
+ error);
+}
+
+gint32
+thrift_protocol_write_set_end (ThriftProtocol *protocol, GError **error)
+{
+ return THRIFT_PROTOCOL_GET_CLASS (protocol)->write_set_end (protocol,
+ error);
+}
+
+gint32
+thrift_protocol_write_bool (ThriftProtocol *protocol,
+ const gboolean value, GError **error)
+{
+ return THRIFT_PROTOCOL_GET_CLASS (protocol)->write_bool (protocol, value,
+ error);
+}
+
+gint32
+thrift_protocol_write_byte (ThriftProtocol *protocol, const gint8 value,
+ GError **error)
+{
+ return THRIFT_PROTOCOL_GET_CLASS (protocol)->write_byte (protocol, value,
+ error);
+}
+
+gint32
+thrift_protocol_write_i16 (ThriftProtocol *protocol, const gint16 value,
+ GError **error)
+{
+ return THRIFT_PROTOCOL_GET_CLASS (protocol)->write_i16 (protocol, value,
+ error);
+}
+
+gint32
+thrift_protocol_write_i32 (ThriftProtocol *protocol, const gint32 value,
+ GError **error)
+{
+ return THRIFT_PROTOCOL_GET_CLASS (protocol)->write_i32 (protocol, value,
+ error);
+}
+
+gint32
+thrift_protocol_write_i64 (ThriftProtocol *protocol, const gint64 value,
+ GError **error)
+{
+ return THRIFT_PROTOCOL_GET_CLASS (protocol)->write_i64 (protocol, value,
+ error);
+}
+
+gint32
+thrift_protocol_write_double (ThriftProtocol *protocol,
+ const gdouble value, GError **error)
+{
+ return THRIFT_PROTOCOL_GET_CLASS (protocol)->write_double (protocol,
+ value, error);
+}
+
+gint32
+thrift_protocol_write_string (ThriftProtocol *protocol,
+ const gchar *str, GError **error)
+{
+ return THRIFT_PROTOCOL_GET_CLASS (protocol)->write_string (protocol, str,
+ error);
+}
+
+gint32
+thrift_protocol_write_binary (ThriftProtocol *protocol, const gpointer buf,
+ const guint32 len, GError **error)
+{
+ return THRIFT_PROTOCOL_GET_CLASS (protocol)->write_binary (protocol, buf,
+ len, error);
+}
+
+gint32
+thrift_protocol_read_message_begin (ThriftProtocol *protocol,
+ gchar **name,
+ ThriftMessageType *message_type,
+ gint32 *seqid, GError **error)
+{
+ return THRIFT_PROTOCOL_GET_CLASS (protocol)->read_message_begin (protocol,
+ name, message_type,
+ seqid, error);
+}
+
+gint32
+thrift_protocol_read_message_end (ThriftProtocol *protocol,
+ GError **error)
+{
+ return THRIFT_PROTOCOL_GET_CLASS (protocol)->read_message_end (protocol,
+ error);
+}
+
+gint32
+thrift_protocol_read_struct_begin (ThriftProtocol *protocol,
+ gchar **name,
+ GError **error)
+{
+ return THRIFT_PROTOCOL_GET_CLASS (protocol)->read_struct_begin (protocol,
+ name,
+ error);
+}
+
+gint32
+thrift_protocol_read_struct_end (ThriftProtocol *protocol, GError **error)
+{
+ return THRIFT_PROTOCOL_GET_CLASS (protocol)->read_struct_end (protocol,
+ error);
+}
+
+gint32
+thrift_protocol_read_field_begin (ThriftProtocol *protocol,
+ gchar **name,
+ ThriftType *field_type,
+ gint16 *field_id,
+ GError **error)
+{
+ return THRIFT_PROTOCOL_GET_CLASS (protocol)->read_field_begin (protocol,
+ name,
+ field_type,
+ field_id,
+ error);
+}
+
+gint32
+thrift_protocol_read_field_end (ThriftProtocol *protocol,
+ GError **error)
+{
+ return THRIFT_PROTOCOL_GET_CLASS (protocol)->read_field_end (protocol,
+ error);
+}
+
+gint32
+thrift_protocol_read_map_begin (ThriftProtocol *protocol,
+ ThriftType *key_type,
+ ThriftType *value_type, guint32 *size,
+ GError **error)
+{
+ return THRIFT_PROTOCOL_GET_CLASS (protocol)->read_map_begin (protocol,
+ key_type,
+ value_type,
+ size,
+ error);
+}
+
+gint32
+thrift_protocol_read_map_end (ThriftProtocol *protocol, GError **error)
+{
+ return THRIFT_PROTOCOL_GET_CLASS (protocol)->read_map_end (protocol,
+ error);
+}
+
+gint32
+thrift_protocol_read_list_begin (ThriftProtocol *protocol,
+ ThriftType *element_type,
+ guint32 *size, GError **error)
+{
+ return THRIFT_PROTOCOL_GET_CLASS (protocol)->read_list_begin (protocol,
+ element_type,
+ size, error);
+}
+
+gint32
+thrift_protocol_read_list_end (ThriftProtocol *protocol, GError **error)
+{
+ return THRIFT_PROTOCOL_GET_CLASS (protocol)->read_list_end (protocol,
+ error);
+}
+
+gint32
+thrift_protocol_read_set_begin (ThriftProtocol *protocol,
+ ThriftType *element_type,
+ guint32 *size, GError **error)
+{
+ return THRIFT_PROTOCOL_GET_CLASS (protocol)->read_set_begin (protocol,
+ element_type,
+ size, error);
+}
+
+gint32
+thrift_protocol_read_set_end (ThriftProtocol *protocol, GError **error)
+{
+ return THRIFT_PROTOCOL_GET_CLASS (protocol)->read_set_end (protocol,
+ error);
+}
+
+gint32
+thrift_protocol_read_bool (ThriftProtocol *protocol, gboolean *value,
+ GError **error)
+{
+ return THRIFT_PROTOCOL_GET_CLASS (protocol)->read_bool (protocol, value,
+ error);
+}
+
+gint32
+thrift_protocol_read_byte (ThriftProtocol *protocol, gint8 *value,
+ GError **error)
+{
+ return THRIFT_PROTOCOL_GET_CLASS (protocol)->read_byte (protocol, value,
+ error);
+}
+
+gint32
+thrift_protocol_read_i16 (ThriftProtocol *protocol, gint16 *value,
+ GError **error)
+{
+ return THRIFT_PROTOCOL_GET_CLASS (protocol)->read_i16 (protocol, value,
+ error);
+}
+
+gint32
+thrift_protocol_read_i32 (ThriftProtocol *protocol, gint32 *value,
+ GError **error)
+{
+ return THRIFT_PROTOCOL_GET_CLASS (protocol)->read_i32 (protocol, value,
+ error);
+}
+
+gint32
+thrift_protocol_read_i64 (ThriftProtocol *protocol, gint64 *value,
+ GError **error)
+{
+ return THRIFT_PROTOCOL_GET_CLASS (protocol)->read_i64 (protocol, value,
+ error);
+}
+
+gint32
+thrift_protocol_read_double (ThriftProtocol *protocol,
+ gdouble *value, GError **error)
+{
+ return THRIFT_PROTOCOL_GET_CLASS (protocol)->read_double (protocol, value,
+ error);
+}
+
+gint32
+thrift_protocol_read_string (ThriftProtocol *protocol,
+ gchar **str, GError **error)
+{
+ return THRIFT_PROTOCOL_GET_CLASS (protocol)->read_string (protocol, str,
+ error);
+}
+
+gint32
+thrift_protocol_read_binary (ThriftProtocol *protocol, gpointer *buf,
+ guint32 *len, GError **error)
+{
+ return THRIFT_PROTOCOL_GET_CLASS (protocol)->read_binary (protocol, buf,
+ len, error);
+}
+
+gint32
+thrift_protocol_skip (ThriftProtocol *protocol, ThriftType type, GError **error)
+{
+ switch (type)
+ {
+ case T_BOOL:
+ {
+ gboolean boolv;
+ return thrift_protocol_read_bool (protocol, &boolv, error);
+ }
+ case T_BYTE:
+ {
+ gint8 bytev;
+ return thrift_protocol_read_byte (protocol, &bytev, error);
+ }
+
+ case T_I16:
+ {
+ gint16 i16;
+ return thrift_protocol_read_i16 (protocol, &i16, error);
+ }
+ case T_I32:
+ {
+ gint32 i32;
+ return thrift_protocol_read_i32 (protocol, &i32, error);
+ }
+ case T_I64:
+ {
+ gint64 i64;
+ return thrift_protocol_read_i64 (protocol, &i64, error);
+ }
+ case T_DOUBLE:
+ {
+ gdouble dub;
+ return thrift_protocol_read_double (protocol, &dub, error);
+ }
+ case T_STRING:
+ {
+ gpointer data;
+ guint32 len;
+ gint32 ret = thrift_protocol_read_binary (protocol, &data, &len, error);
+ g_free (data);
+ return ret;
+ }
+ case T_STRUCT:
+ {
+ guint32 result = 0;
+ gchar *name;
+ gint16 fid;
+ ThriftType ftype;
+ result += thrift_protocol_read_struct_begin (protocol, &name, error);
+
+ while (1)
+ {
+ result += thrift_protocol_read_field_begin (protocol, &name, &ftype,
+ &fid, error);
+ if (ftype == T_STOP)
+ {
+ break;
+ }
+ result += thrift_protocol_skip (protocol, ftype, error);
+ result += thrift_protocol_read_field_end (protocol, error);
+ }
+ result += thrift_protocol_read_struct_end (protocol, error);
+ return result;
+ }
+ case T_MAP:
+ {
+ guint32 result = 0;
+ ThriftType elem_type;
+ guint32 i, size;
+ result += thrift_protocol_read_set_begin (protocol, &elem_type, &size,
+ error);
+ for (i = 0; i < size; i++)
+ {
+ result += thrift_protocol_skip (protocol, elem_type, error);
+ }
+ result += thrift_protocol_read_set_end (protocol, error);
+ return result;
+ }
+ case T_LIST:
+ {
+ guint32 result = 0;
+ ThriftType elem_type;
+ guint32 i, size;
+ result += thrift_protocol_read_list_begin (protocol, &elem_type, &size,
+ error);
+ for (i = 0; i < size; i++)
+ {
+ result += thrift_protocol_skip (protocol, elem_type, error);
+ }
+ result += thrift_protocol_read_list_end (protocol, error);
+ return result;
+ }
+ default:
+ return 0;
+ }
+}
+
+/* define the GError domain for Thrift protocols */
+GQuark
+thrift_protocol_error_quark (void)
+{
+ return g_quark_from_static_string (THRIFT_PROTOCOL_ERROR_DOMAIN);
+}
+