Encode by this lib,can't be decode by java lib
Encode by this lib,can't be decode by java lib,version 0.6.12
You need to show your input data, or encoded data, if you want any comments.
The result is Uint8Array after encode by js-lib,But decoding in java need a byte,How js-lib encode it to Int8Array?
Uint8Array is just an array of bytes. https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Uint8Array
For js:
var source = {userId: 18662, grade: 66, nickName: 'qwe'}; var uint8Arr = msgpack.encode(source); console.log(uint8Arr instanceof Uint8Array);// print: true console.log(uint8Arr);// print:[131,166,117,115,101,114,73,100,205,72,230,165,103,114,97,100,101,66,168,110,105,99,107,78,97,109,101,163,113,119,101]
For Java: SimpleObj obj = new SimpleObj(); obj.setUserId(18662); obj.setGrade(66); obj.setNickName("qwe"); MessagePack pack = new MessagePack(); byte[] bs = pack.write(obj); System.out.println(Arrays.toString(bs));//print: [-109, -51, 72, -26, 66, -93, 113, 119, 101]
How can I transfer the data and decode it between them?
Try http://kawanet.github.io/msgpack-lite/ and ask it to Java lib maintainer.
[-109, -51, 72, -26, 66, -93, 113, 119, 101] represents an array:
[
18662,
66,
"qwe"
]
[131,166,117,115,101,114,73,100,205,72,230,165,103,114,97,100,101,66,168,110,105,99,107,78,97,109,101,163,113,119,101] represents a plain object:
{
"userId": 18662,
"grade": 66,
"nickName": "qwe"
}