stomp-js icon indicating copy to clipboard operation
stomp-js copied to clipboard

Binary data is not handled

Open francoisforster opened this issue 14 years ago • 9 comments

I'm sending the following bytes from java: 45,-113,4,-120 and on the node.js side I get: 45 65533 4 65533 for (i=0;i<message.body.length;i++) { console.log(message.body.charCodeAt(i)); }

STOMP supports binary data, so I would expect it it be handled with Buffers instead of strings.

francoisforster avatar Dec 30 '11 20:12 francoisforster

I'll take a look at this. You're right though, if it's a bytes message, it should use buffers instead of strings.

benjaminws avatar Dec 30 '11 20:12 benjaminws

Can you please try out branch issue-15 (https://github.com/benjaminws/stomp-js/tree/issue-15). All it does is convert the body of the message back to a buffer if it's detected that the message is a binary message (by the presence of content-length header).

benjaminws avatar Dec 30 '11 20:12 benjaminws

That doesn't help. The bytes are already lost in translation before that.

francoisforster avatar Dec 30 '11 21:12 francoisforster

Doh, you're right. I'll try another approach. This whole codebase needs a major refactoring :(

benjaminws avatar Dec 30 '11 21:12 benjaminws

New approach will leave the buffer intact, only slicing out the command/header bits as needed. Can you pull it down and test it for yourself?

benjaminws avatar Dec 30 '11 22:12 benjaminws

Looked at this again. Problem is more annoying that I initially thought. Working on a fix, though. Should have something cooked up tomorrow.

benjaminws avatar Jan 02 '12 04:01 benjaminws

The body is still not a buffer (it's a Frame) which still mangles up the bytes.

francoisforster avatar Jan 03 '12 15:01 francoisforster

Right. Hence the last note. Will hopefully have a fix today. The problem is the way I'm handling the incoming buffer, trying to treat it as a string initially instead of a buffer. Needs some extra work to parse out what I need from the buffer (no niceties like split, indexOf, etc on a buffer).

benjaminws avatar Jan 03 '12 15:01 benjaminws

Greatly appreciate your work.

francoisforster avatar Jan 03 '12 15:01 francoisforster