You are viewing a plain text version of this content. The canonical link for it is here.
Posted to proton@qpid.apache.org by "Dominic Evans (JIRA)" <ji...@apache.org> on 2014/11/04 18:02:33 UTC

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

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

Dominic Evans commented on PROTON-736:
--------------------------------------

[~mcpierce] as discussed on IRC

The problem here is that ruby doesn't really differentiate between Binary data and (utf-8) String data. The IO.binread [1] method just reads that data into a string primitive and marks it as rb:ASCII-8BIT to prevent any encoding/decoding or line-ending changes from taking place on it. This can be seen in the mapping.rb code by the fact that the AMQP Binary type has klasses=nil for Ruby.

As such, if you use the message.body= setter and give it a String, you will always end up with the message body being encoded as an AmqpValue containing a String type. However, this is actually a spec-incompliant behaviour, because the spec states that a String type will only contain UTF-8 encoded data. Hence, if you try to receive that message using either a proton-j or python client the String will fail to decode.

Its not obvious what the correct fix here would be, but I'd suggest something along the lines of:
1) raise an exception in msg.body= if you pass a string primitive that doesn't contain valid UTF-8 
2) add the ability in message.rb to set your own arbitary Qpid::Proton::Data object as the message body and map to and from that rather than ruby primitives if it has been used




-- 
[1] http://ruby-doc.org/core-1.9.2/IO.html#method-c-binread

> 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
>         Attachments: 0001-PROTON-736-Ruby-Message-does-not-return-all-content.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)