You are viewing a plain text version of this content. The canonical link for it is here.
Posted to proton@qpid.apache.org by "Rafael H. Schloming (JIRA)" <ji...@apache.org> on 2014/11/08 14:38:34 UTC

[jira] [Reopened] (PROTON-736) ruby: unable to send binary data?

     [ https://issues.apache.org/jira/browse/PROTON-736?page=com.atlassian.jira.plugin.system.issuetabpanels:all-tabpanel ]

Rafael H. Schloming reopened PROTON-736:
----------------------------------------

The semantics described in the commit are going to result in interop issues with lots of other clients.

Choosing whether to encode as string(utf8) vs binary based on the values passed in is fundamentally broken. To understand why, imagine if I write a ruby client that reads a bunch of binary files from a directory and sends them in the body of a message to a Java client. Now let's say all of these files contain binary data, say some sort of gzipped thing. Now let's further say that some of these files coincidentally happen to contain bytes that are only in the range 0-127. The semantics you have described will result in some of these files getting sent as text messages and some of these files getting sent as data. This will come out as different message types to a Java client, or if the values appear in a map or list, they will be deseriaized as Strings rather than byte[].

Basically, the upshot is by choosing based on the content of the string, every other AMQP client will need to check and deal with the possibility of both string and binary values wherever they expect a binary value, and since nobody expects to have to do this (and indeed even if they did it is incredibly cumbersome to have to do so), you will get lots of really terrible interop bugs.

> ruby: unable to send binary data?
> ---------------------------------
>
>                 Key: PROTON-736
>                 URL: https://issues.apache.org/jira/browse/PROTON-736
>             Project: Qpid Proton
>          Issue Type: Bug
>          Components: ruby-binding
>    Affects Versions: 0.8
>            Reporter: Dominic Evans
>            Assignee: Darryl L. Pierce
>             Fix For: 0.9
>
>         Attachments: 0001-PROTON-736-Ruby-Message-does-not-return-all-content.patch, 0002-PROTON-736-Only-encode-Ruby-strings-as-UTF-8-if-it-s.patch
>
>
> As discussed on irc with [~mcpierce]
> I've not been able to determine how I can correctly send binary data using the ruby gem.
> From proton-c I can do this by (e.g.,)
> {{
> char* msgdata = Buffer::Data(buffer);
> size_t msglen = Buffer::Length(buffer);
> pn_message_set_format(msg->message, PN_DATA);
> pn_message_load_data(msg->message, msgdata, msglen);
> }}
> and I assumed I might be able to do similar from Ruby by (e.g.,)
> {{
> data = File.binread(filename)
> msg.format = Qpid::Proton::MessageFormat::DATA
> msg.content = data
> }}
> But Ruby is reading the data into a string and the SWIG binding is still expecting a byte* array here.
> After our discussions on IRC I also investigated doing:
> {{
> filedata = File.binread(filename)
> data = Qpid::Proton::Data.new
> data.binary = filedata
> msg.body = data
> }}
> but didn't have any luck with this approach either.



--
This message was sent by Atlassian JIRA
(v6.3.4#6332)