在android上使用messagepack,可以序列化/反序列化一个类,但不是绝对正确的。
简单的测试类:
@Message
public class Account {
public String Code;
public int Sequence;
public float Lot;
public String toString(){
return "Seq:"+Sequence;
}
}
测试代码:</p>
MessagePack msgpack = new MessagePack();
msgpack.register(Account.class);
try {
Account a = new Account();
a.Code ="name";
a.Sequence = 105;
a.Lot = (float)1.05;
byte[] b = msgpack.write(a);
//byte[] c = MessagePack.pack(a);
Account aa = msgpack.read(b, Account.class );
System.out.println(new String(b));
System.out.println("test00: aa.Lot "+aa.Lot);
}catch(IOException e){
e.printStackTrace();
}
运行后“byte[] b = msgpack.write(a);” 在 android 上,输出字节数组 b[] 不正确(与 java 相比)
[-109, -92, 110, 97, 109, 101, 105, -54, 63, -122, 102, 102] on java
[-109, -92, 110, 97, 109, 101, -54, 63, -122, 102, 102, 105] on android