I'm sending binary data over WebSocket to a Python application. This binary data is decoded by calling struct.unpack("BH", data")
on it, requiring a 4-long bytes object.
The problem I'm currently facing is, that all data contains duplicate backslashes, even in arraybuffer
mode and is therefor 16 bytes long. I can't detect the varying size because there is data appended to the back of it (irrelevant for this question) and even if I could, I also couldn't find a way to strip the backslashes in Python.
How the data is sent:
// this.webSocket.binaryType = "arraybuffer";
var message = "\\x05\\x00\\x00\\x00"; // escaping required
var buffer = new Int8Array(message.length);
for (var i = 0; i < message.length; i++) {
buffer[i] = message.charCodeAt(i);
}
this.webSocket.send(buffer.buffer);
In comparison, this is how said data looks when defined in Python:
b'\x05\x00\x00\x00'
And this is how it looks as a received message:
b'\\x05\\x00\\x00\\x00'
The ideal solution for this issue would be on the JavaScript-side because I can't really change the implementation of the Python application without breaking Python-based clients.