summaryrefslogtreecommitdiff
path: root/test/c_glib
diff options
context:
space:
mode:
authorChandler May <cjmay4754@gmail.com>2016-01-10 06:01:10 +0000
committerJens Geyer <jensg@apache.org>2016-01-19 22:00:27 +0100
commit6dde90be2e15ae84e84671274e034643a33d738f (patch)
treece6a274b06c81add33913edb79746f185542b972 /test/c_glib
parente917a278d836ad9cceba8ea5054346b22b3bbbb7 (diff)
downloadthrift-6dde90be2e15ae84e84671274e034643a33d738f.tar.gz
THRIFT-1313 implement compact protocol for c_glib library
Client: C_glib Chandler May <cjmay4754@gmail.com> This closes #795
Diffstat (limited to 'test/c_glib')
-rw-r--r--test/c_glib/src/test_client.c16
-rw-r--r--test/c_glib/src/test_server.c34
2 files changed, 38 insertions, 12 deletions
diff --git a/test/c_glib/src/test_client.c b/test/c_glib/src/test_client.c
index 0f8a713f2..3ae9325d4 100644
--- a/test/c_glib/src/test_client.c
+++ b/test/c_glib/src/test_client.c
@@ -27,6 +27,7 @@
#include <thrift/c_glib/thrift.h>
#include <thrift/c_glib/protocol/thrift_binary_protocol.h>
+#include <thrift/c_glib/protocol/thrift_compact_protocol.h>
#include <thrift/c_glib/transport/thrift_buffered_transport.h>
#include <thrift/c_glib/transport/thrift_framed_transport.h>
#include <thrift/c_glib/transport/thrift_socket.h>
@@ -89,7 +90,7 @@ main (int argc, char **argv)
{ "transport", 0, 0, G_OPTION_ARG_STRING, &transport_option,
"Transport: buffered, framed (=buffered)", NULL },
{ "protocol", 0, 0, G_OPTION_ARG_STRING, &protocol_option,
- "Protocol: binary (=binary)", NULL },
+ "Protocol: binary, compact (=binary)", NULL },
{ "testloops", 'n', 0, G_OPTION_ARG_INT, &num_tests,
"Number of tests (=1)", NULL },
{ NULL }
@@ -141,10 +142,15 @@ main (int argc, char **argv)
host = g_strdup ("localhost");
/* Validate the parsed options */
- if (protocol_option != NULL &&
- strncmp (protocol_option, "binary", 7) != 0) {
- fprintf (stderr, "Unknown protocol type %s\n", protocol_option);
- options_valid = FALSE;
+ if (protocol_option != NULL) {
+ if (strncmp (protocol_option, "compact", 8) == 0) {
+ protocol_type = THRIFT_TYPE_COMPACT_PROTOCOL;
+ protocol_name = "compact";
+ }
+ else if (strncmp (protocol_option, "binary", 7) != 0) {
+ fprintf (stderr, "Unknown protocol type %s\n", protocol_option);
+ options_valid = FALSE;
+ }
}
if (transport_option != NULL) {
diff --git a/test/c_glib/src/test_server.c b/test/c_glib/src/test_server.c
index 13eec277a..7f41d3f89 100644
--- a/test/c_glib/src/test_server.c
+++ b/test/c_glib/src/test_server.c
@@ -24,6 +24,7 @@
#include <thrift/c_glib/thrift.h>
#include <thrift/c_glib/protocol/thrift_binary_protocol_factory.h>
+#include <thrift/c_glib/protocol/thrift_compact_protocol_factory.h>
#include <thrift/c_glib/server/thrift_server.h>
#include <thrift/c_glib/server/thrift_simple_server.h>
#include <thrift/c_glib/transport/thrift_buffered_transport.h>
@@ -68,6 +69,8 @@ main (int argc, char **argv)
static gchar *server_type_option = NULL;
static gchar *transport_option = NULL;
static gchar *protocol_option = NULL;
+ static gint string_limit = 0;
+ static gint container_limit = 0;
static
GOptionEntry option_entries[] = {
@@ -78,7 +81,11 @@ main (int argc, char **argv)
{ "transport", 0, 0, G_OPTION_ARG_STRING, &transport_option,
"Transport: buffered, framed (=buffered)", NULL },
{ "protocol", 0, 0, G_OPTION_ARG_STRING, &protocol_option,
- "Protocol: binary (=binary)", NULL },
+ "Protocol: binary, compact (=binary)", NULL },
+ { "string-limit", 0, 0, G_OPTION_ARG_INT, &string_limit,
+ "Max string length (=none)", NULL },
+ { "container-limit", 0, 0, G_OPTION_ARG_INT, &container_limit,
+ "Max container length (=none)", NULL },
{ NULL }
};
@@ -126,10 +133,15 @@ main (int argc, char **argv)
options_valid = FALSE;
}
- if (protocol_option != NULL &&
- strncmp (protocol_option, "binary", 7) != 0) {
- fprintf (stderr, "Unknown protocol type %s\n", protocol_option);
- options_valid = FALSE;
+ if (protocol_option != NULL) {
+ if (strncmp (protocol_option, "compact", 8) == 0) {
+ protocol_factory_type = THRIFT_TYPE_COMPACT_PROTOCOL_FACTORY;
+ protocol_name = "compact";
+ }
+ else if (strncmp (protocol_option, "binary", 7) != 0) {
+ fprintf (stderr, "Unknown protocol type %s\n", protocol_option);
+ options_valid = FALSE;
+ }
}
if (transport_option != NULL) {
@@ -157,8 +169,16 @@ main (int argc, char **argv)
NULL);
transport_factory = g_object_new (transport_factory_type,
NULL);
- protocol_factory = g_object_new (protocol_factory_type,
- NULL);
+
+ if (strncmp (protocol_name, "compact", 8) == 0) {
+ protocol_factory = g_object_new (protocol_factory_type,
+ "string_limit", string_limit,
+ "container_limit", container_limit,
+ NULL);
+ } else {
+ protocol_factory = g_object_new (protocol_factory_type,
+ NULL);
+ }
server = g_object_new (THRIFT_TYPE_SIMPLE_SERVER,
"processor", processor,