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

Encode by this lib,can't be decode by java lib #64

Open
lasting0001 opened this issue Feb 21, 2017 · 5 comments
Open

Encode by this lib,can't be decode by java lib #64

lasting0001 opened this issue Feb 21, 2017 · 5 comments

Comments

@lasting0001
Copy link

Encode by this lib,can't be decode by java lib,version 0.6.12

@kawanet
Copy link
Owner

kawanet commented Feb 21, 2017

You need to show your input data, or encoded data, if you want any comments.

@lasting0001
Copy link
Author

The result is Uint8Array after encode by js-lib,But decoding in java need a byte,How js-lib encode it to Int8Array?

@kawanet
Copy link
Owner

kawanet commented Feb 21, 2017

@lasting0001
Copy link
Author

For js:

<script src="./msgpack.min.js"></script>

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?

@kawanet
Copy link
Owner

kawanet commented Feb 22, 2017

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"
}

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