THRIFT-1766 [Ruby] Provide support for binary types
Patch: Vanja Bucic
diff --git a/lib/rb/ext/struct.c b/lib/rb/ext/struct.c
index 313da4c..f500d03 100644
--- a/lib/rb/ext/struct.c
+++ b/lib/rb/ext/struct.c
@@ -75,6 +75,11 @@
return Qnil;
}
+VALUE default_write_binary(VALUE protocol, VALUE value) {
+ rb_funcall(protocol, write_binary_method_id, 1, value);
+ return Qnil;
+}
+
VALUE default_write_list_begin(VALUE protocol, VALUE etype, VALUE length) {
rb_funcall(protocol, write_list_begin_method_id, 2, etype, length);
return Qnil;
@@ -190,6 +195,10 @@
return rb_funcall(protocol, read_string_method_id, 0);
}
+VALUE default_read_binary(VALUE protocol) {
+ return rb_funcall(protocol, read_binary_method_id, 0);
+}
+
VALUE default_read_struct_begin(VALUE protocol) {
return rb_funcall(protocol, read_struct_begin_method_id, 0);
}
@@ -327,7 +336,12 @@
} else if (ttype == TTYPE_DOUBLE) {
default_write_double(protocol, value);
} else if (ttype == TTYPE_STRING) {
- default_write_string(protocol, value);
+ VALUE is_binary = rb_hash_aref(field_info, binary_sym);
+ if (is_binary != Qtrue) {
+ default_write_string(protocol, value);
+ } else {
+ default_write_binary(protocol, value);
+ }
} else if (IS_CONTAINER(ttype)) {
write_container(ttype, field_info, value, protocol);
} else if (ttype == TTYPE_STRUCT) {
@@ -430,7 +444,12 @@
} else if (ttype == TTYPE_I64) {
result = default_read_i64(protocol);
} else if (ttype == TTYPE_STRING) {
- result = default_read_string(protocol);
+ VALUE is_binary = rb_hash_aref(field_info, binary_sym);
+ if (is_binary != Qtrue) {
+ result = default_read_string(protocol);
+ } else {
+ result = default_read_binary(protocol);
+ }
} else if (ttype == TTYPE_DOUBLE) {
result = default_read_double(protocol);
} else if (ttype == TTYPE_STRUCT) {