Closed JSteunou closed 8 years ago
Array buffer sounds like a JavaScript data structure. Can you post your code, please?
function unicodeStringToTypedArray(s) {
let escstr = encodeURIComponent(s);
let binstr = escstr.replace(/%([0-9A-F]{2})/g, (match, p1) => String.fromCharCode('0x' + p1));
let arr = Array.prototype.map.call(s, (c) => c.charCodeAt(0));
return new Uint8Array(arr);
}
I'm using this to convert String frame created by stomp.js plugin.
We have exactly the same code for handling text vs binary frames (array i believe sends a binary). The only difference is the lack of utf-8 check on binary. If I had to guess I would think the error is in your code. Can you convert your array back to a string?
var arr = [83,69,78,68,10,100,101,115,116,105,110,97,116,105,111,110,58,47,116,111,112,105,99,47,119,101,98,115,116,111,109,112,45,99,104,97,116,45,101,120,97,109,112,108,101,10,99,111,110,116,101,110,116,45,108,101,110,103,116,104,58,51,49,10,10,123,34,97,117,116,104,111,114,34,58,34,85,115,101,114,32,49,34,44,34,116,101,120,116,34,58,34,185,34,125,0];
var binstr = String.fromCharCode(...new Uint8Array(arr));
binstr
"SEND
destination:/topic/webstomp-chat-example
content-length:31
{"author":"User 1","text":"¹"}
and last char is null byte
I can invite you on my gitlab project if it helps @essen
Well 185 isn't a valid UTF-8 value so the error is definitely in the encoding. :-)
I see. I must have the same error twice in decode and in encode function Le 28 mars 2016 1:11 PM, "Loïc Hoguin" notifications@github.com a écrit :
Well 185 isn't a valid UTF-8 value so the error is definitely in the encoding. :-)
— You are receiving this because you authored the thread. Reply to this email directly or view it on GitHub https://github.com/rabbitmq/rabbitmq-web-stomp/issues/54#issuecomment-202343428
Pfff find it, silly bug in my encode function. I built my array with the original string, not the escaped one. And even if it's not valid as an utf-8 value, browser can still decode it so I did not see any error in the decode process. See
String.fromCharCode(185)
"¹"
oO
Thank you for pointing me in the right direction @essen!
Hi again ;)
I tried to use the arraybuffer mode. No issue when sending classical data, but I got a crash when sending utf-8 encoded data for chars like ¹ for example. The String version of the frame works fine, but the arraybuffer version is not. Maybe my encoding is wrong, but I feel pretty confident about it because it's quite the same than web-stomp send me back when I'm sending the String version.
string frame (with null byte at the end)
arraybuffer frame
error browser side
STOMP died
error rmq log
/etc/rabbitmq/rabbitmq.config
to sum it up: no issue when sending data in a String or ArrayBuffer frame when the body do not contain utf-8 encoded char. But when it is present, it crashes only in ArrayBuffer mode.