[ 
https://issues.apache.org/jira/browse/THRIFT-1766?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=13951330#comment-13951330
 ] 

Vanja Bucic commented on THRIFT-1766:
-------------------------------------

We are currently using my patched gem internally for testing. 
It turns out that the struct.c, as included in the ruby gem at least, has no 
code that would check for 'binary' attribute. The master dispatch function is 
not differentiating STRING from BINARY STRING as seen here:
{code:title=struct.c}
static void write_anything(int ttype, VALUE value, VALUE protocol, VALUE 
field_info) {
  if (ttype == TTYPE_BOOL) {
    default_write_bool(protocol, value);
  } else if (ttype == TTYPE_BYTE) {
    default_write_byte(protocol, value);
  } else if (ttype == TTYPE_I16) {
    default_write_i16(protocol, value);
  } else if (ttype == TTYPE_I32) {
    default_write_i32(protocol, value);
  } else if (ttype == TTYPE_I64) {
    default_write_i64(protocol, value);
  } else if (ttype == TTYPE_DOUBLE) {
    default_write_double(protocol, value);
  } else if (ttype == TTYPE_STRING) {
    default_write_string(protocol, value);
  } else if (IS_CONTAINER(ttype)) {
    write_container(ttype, field_info, value, protocol);
  } else if (ttype == TTYPE_STRUCT) {
    if (rb_obj_is_kind_of(value, thrift_union_class)) {
      rb_thrift_union_write(value, protocol);
    } else {
      rb_thrift_struct_write(value, protocol);
    }
  } else {
    rb_raise(rb_eNotImpError, "Unknown type for binary_encoding: %d", ttype);
  }
}
{code}

I am assuming that what we want is more like
{code:title=patched_dispatch}
-    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);
+    }
{code}

and similar on the read side.

I'll submit my patch for review this weekend after some more testing.

> [Ruby] Provide support for binary types
> ---------------------------------------
>
>                 Key: THRIFT-1766
>                 URL: https://issues.apache.org/jira/browse/THRIFT-1766
>             Project: Thrift
>          Issue Type: Sub-task
>          Components: Ruby - Library
>    Affects Versions: 0.9
>            Reporter: Nathan Beyer
>            Assignee: Nathan Beyer
>         Attachments: THRIFT-1766-provide-support-for-binary-types.patch
>
>
> The Ruby library didn't provide explicit support for 'binary' types, which 
> sort of worked on Ruby 1.8.7 and with Thrift 0.8, but it doesn't work with 
> Ruby 1.9.3 and the encoding changes that were included with Thrift 0.9.
> This issue is intended to provide first class support for the 'binary' type.



--
This message was sent by Atlassian JIRA
(v6.2#6252)

Reply via email to