Closed ghost closed 9 years ago
Hi @pwnsdx , msgpack-c is C and C++ version of msgpack implementation. Are you using msgpack-c?
Hello redboltz,
Thanks for answering. No I don't use msgpack-c. https://github.com/creationix/msgpack-js-browser looks dead since 2 years. Assuming that msgpack-js-browser respect the standard, I'm posting here to know if msgpack-c have the same problem.
I'm not sure about the msgpack-js-browser. If ArrayBuffer's hex dump is not the same as expected value, you can do the following tests:
Again, I don't know which is a part of msgpack-js-browser library.
Note:
msgpack-c supports the following msgpack format: https://github.com/msgpack/msgpack/blob/master/spec.md
msgpack-c is mapping std::string to str and std::vector
After doing what you said, it looks like the problem is here:
Compressor.utf8 = {
write: function(view, offset, string)
{
var byteLength = view.byteLength;
for(var i = 0, l = string.length; i < l; i++) {
var codePoint = string.charCodeAt(i);
// One byte of UTF-8
if (codePoint < 0x80) {
view.setUint8(offset++, codePoint >>> 0 & 0x7f | 0x00);
continue;
}
// Two bytes of UTF-8
if (codePoint < 0x800) {
view.setUint8(offset++, codePoint >>> 6 & 0x1f | 0xc0);
view.setUint8(offset++, codePoint >>> 0 & 0x3f | 0x80);
continue;
}
// Three bytes of UTF-8
if (codePoint < 0x10000) {
view.setUint8(offset++, codePoint >>> 12 & 0x0f | 0xe0);
view.setUint8(offset++, codePoint >>> 6 & 0x3f | 0x80);
view.setUint8(offset++, codePoint >>> 0 & 0x3f | 0x80);
continue;
}
// Four bytes of UTF-8
if (codePoint < 0x110000) {
view.setUint8(offset++, codePoint >>> 18 & 0x07 | 0xf0);
view.setUint8(offset++, codePoint >>> 12 & 0x3f | 0x80);
view.setUint8(offset++, codePoint >>> 6 & 0x3f | 0x80);
view.setUint8(offset++, codePoint >>> 0 & 0x3f | 0x80);
continue;
}
console.error('Bad codepoint ' + codePoint);
}
},
read: function(view, offset, length)
{
var string = '';
for(var i = offset, end = offset + length; i < end; i++) {
var byte = view.getUint8(i);
// One byte character
if ((byte & 0x80) === 0x00) {
string += String.fromCharCode(byte);
continue;
}
// Two byte character
if ((byte & 0xe0) === 0xc0) {
string += String.fromCharCode(
((byte & 0x0f) << 6) |
(view.getUint8(++i) & 0x3f)
);
continue;
}
// Three byte character
if ((byte & 0xf0) === 0xe0) {
string += String.fromCharCode(
((byte & 0x0f) << 12) |
((view.getUint8(++i) & 0x3f) << 6) |
((view.getUint8(++i) & 0x3f) << 0)
);
continue;
}
// Four byte character
if ((byte & 0xf8) === 0xf0) {
string += String.fromCharCode(
((byte & 0x07) << 18) |
((view.getUint8(++i) & 0x3f) << 12) |
((view.getUint8(++i) & 0x3f) << 6) |
((view.getUint8(++i) & 0x3f) << 0)
);
continue;
}
console.error('Invalid byte ' + byte.toString(16));
}
return string;
},
count: function(string)
{
var count = 0;
for(var i = 0, l = string.length; i < l; i++) {
var codePoint = string.charCodeAt(i);
if (codePoint < 0x80) {
count += 1;
continue;
}
if (codePoint < 0x800) {
count += 2;
continue;
}
if (codePoint < 0x10000) {
count += 3;
continue;
}
if (codePoint < 0x110000) {
count += 4;
continue;
}
console.error('Bad codepoint ' + codePoint);
}
return count;
}
};
I will try to figure out why it is not working as expected. Thanks for the tips.
I switched to BinaryPack. https://github.com/binaryjs/js-binarypack https://github.com/binaryjs/node-binarypack
Everything works fine now. Thanks for your help.
Hello,
I'm using msgpack-js-browser: https://github.com/creationix/msgpack-js-browser
I added some unit tests, here is the full code:
As you can see, everything is working perfectly except:
My question is, is it a problem due to msgpack-js-browser or msgpack implementation ? And if this is msgpack, can these languages support will be added in the future ?
Thanks.