Closed
Description
It is possible to unpack ulong bigger than Long.MAX_VALUE correctly as BigInteger. But it is not possible to pack it correctly - it becomes unsigned.
public static void main(String[] args) throws IOException {
byte[] pack = bytesInQuestion();
// correct unpacking
BigInteger unpackValue = (BigInteger) MsgPackLite.INSTANCE.unpack(new ByteArrayInputStream(pack));
// let's pack it back again
ByteArrayOutputStream out = new ByteArrayOutputStream();
MsgPackLite.INSTANCE.pack(unpackValue, out);
byte[] repack = out.toByteArray();
System.out.println(Arrays.equals(pack, repack));
System.out.println(Arrays.toString(pack));
System.out.println(Arrays.toString(repack));
//false
//[-49, -128, 0, 0, 0, 127, -1, -1, -2]
//[-50, 127, -1, -1, -2]
}
private static byte[] bytesInQuestion() throws IOException {
ByteArrayOutputStream out = new ByteArrayOutputStream();
DataOutputStream dataStream = new DataOutputStream(out);
try {
dataStream.write(MsgPackLite.INSTANCE.MP_UINT64);
dataStream.writeLong(Long.MAX_VALUE + Integer.MAX_VALUE);
return out.toByteArray();
} finally {
dataStream.close();
}
}
Metadata
Metadata
Assignees
Labels
No labels