mirror of
https://github.com/msgpack/msgpack-python.git
synced 2026-02-09 11:20:14 +00:00
java: adds Unpacker.unpackBigInteger()
This commit is contained in:
parent
1d17836b7d
commit
b4c98584db
3 changed files with 55 additions and 4 deletions
|
|
@ -19,7 +19,7 @@ package org.msgpack;
|
|||
|
||||
import java.io.IOException;
|
||||
import java.nio.ByteBuffer;
|
||||
//import java.math.BigInteger;
|
||||
import java.math.BigInteger;
|
||||
|
||||
abstract class BufferedUnpackerImpl extends UnpackerImpl {
|
||||
int offset = 0;
|
||||
|
|
@ -198,8 +198,7 @@ abstract class BufferedUnpackerImpl extends UnpackerImpl {
|
|||
{
|
||||
long o = castBuffer.getLong(0);
|
||||
if(o < 0) {
|
||||
// FIXME unpackBigInteger
|
||||
throw new MessageTypeException("uint 64 bigger than 0x7fffffff is not supported");
|
||||
throw new MessageTypeException();
|
||||
}
|
||||
advance(9);
|
||||
return o;
|
||||
|
|
@ -231,7 +230,25 @@ abstract class BufferedUnpackerImpl extends UnpackerImpl {
|
|||
}
|
||||
}
|
||||
|
||||
// FIXME unpackBigInteger
|
||||
final BigInteger unpackBigInteger() throws IOException, MessageTypeException {
|
||||
more(1);
|
||||
int b = buffer[offset];
|
||||
if((b & 0xff) != 0xcf) {
|
||||
return BigInteger.valueOf(unpackLong());
|
||||
}
|
||||
|
||||
// unsigned int 64
|
||||
more(9);
|
||||
castBuffer.rewind();
|
||||
castBuffer.put(buffer, offset+1, 8);
|
||||
advance(9);
|
||||
long o = castBuffer.getLong(0);
|
||||
if(o < 0) {
|
||||
return new BigInteger(1, castBuffer.array());
|
||||
} else {
|
||||
return BigInteger.valueOf(o);
|
||||
}
|
||||
}
|
||||
|
||||
final float unpackFloat() throws IOException, MessageTypeException {
|
||||
more(1);
|
||||
|
|
|
|||
|
|
@ -22,6 +22,7 @@ import java.io.InputStream;
|
|||
import java.io.IOException;
|
||||
import java.util.Iterator;
|
||||
import java.nio.ByteBuffer;
|
||||
import java.math.BigInteger;
|
||||
|
||||
/**
|
||||
* Unpacker enables you to deserialize objects from stream.
|
||||
|
|
@ -452,6 +453,15 @@ public class Unpacker implements Iterable<MessagePackObject> {
|
|||
return impl.unpackLong();
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets one {@code BigInteger} value from the buffer.
|
||||
* This method calls {@link fill()} method if needed.
|
||||
* @throws MessageTypeException the first value of the buffer is not a {@code BigInteger}.
|
||||
*/
|
||||
public BigInteger unpackBigInteger() throws IOException, MessageTypeException {
|
||||
return impl.unpackBigInteger();
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets one {@code float} value from the buffer.
|
||||
* This method calls {@link fill()} method if needed.
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue