Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

How to encode an image stored in a Uint8Array? #73

Open
vasconce1o opened this issue May 28, 2017 · 2 comments
Open

How to encode an image stored in a Uint8Array? #73

vasconce1o opened this issue May 28, 2017 · 2 comments

Comments

@vasconce1o
Copy link

I am trying to send an image as part of an object from a web browser, the image is stored in a Uint8Array, but it is encoded to a map, the code is as follows:

var msg = new Object;
msg.op = 'image';
var ia = new Uint8Array(arraybuffer);
msg.image = ia;
var buffer = msgpack.encode(msg);
websocket.send(buffer)

Is there any way to do this, thanks in advance.

@kawanet
Copy link
Owner

kawanet commented Jun 3, 2017

@vasconce1o, Uint8Array looks that it could be encoded and decoded, correctly.

var source = new Uint8Array([1,2,3,4]);
var encoded = msgpack.encode(source);
var decoded = msgpack.decode(encoded);
decoded instanceof Uint8Array; // => true

JSON.stringify, which does not support Uint8Array, would encode it as a Map, however.

JSON.stringify(source); // => "{"0":1,"1":2,"2":3,"3":4}"
JSON.stringify(decoded); // => "{"0":1,"1":2,"2":3,"3":4}"

How you find that your image is encoded to a map?

@vasconce1o
Copy link
Author

@kawanet I am using MessagePack for Qt on the server side and I am receiving code 0x83 that corresponds to the map instead of receiving a bin8 - 0xc4, bin16 - 0xc5, or bin32 - 0xc6 code.

Thanks

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants