summaryrefslogtreecommitdiff
path: root/java/src/main
diff options
context:
space:
mode:
authorfrsyuki <frsyuki@users.sourceforge.jp>2010-08-19 01:19:34 +0900
committerfrsyuki <frsyuki@users.sourceforge.jp>2010-08-19 01:19:34 +0900
commitb4c98584db002cbb4d3960b6ed025212248dcce8 (patch)
treeeb1447469b02b154482e0513db3222e4e205bc3f /java/src/main
parent1d17836b7d2eb4e5e0f25d2466df70e137642061 (diff)
downloadmsgpack-python-b4c98584db002cbb4d3960b6ed025212248dcce8.tar.gz
java: adds Unpacker.unpackBigInteger()
Diffstat (limited to 'java/src/main')
-rw-r--r--java/src/main/java/org/msgpack/BufferedUnpackerImpl.java25
-rw-r--r--java/src/main/java/org/msgpack/Unpacker.java10
2 files changed, 31 insertions, 4 deletions
diff --git a/java/src/main/java/org/msgpack/BufferedUnpackerImpl.java b/java/src/main/java/org/msgpack/BufferedUnpackerImpl.java
index 9496238..5b449c7 100644
--- a/java/src/main/java/org/msgpack/BufferedUnpackerImpl.java
+++ b/java/src/main/java/org/msgpack/BufferedUnpackerImpl.java
@@ -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);
diff --git a/java/src/main/java/org/msgpack/Unpacker.java b/java/src/main/java/org/msgpack/Unpacker.java
index 3a95243..3cae502 100644
--- a/java/src/main/java/org/msgpack/Unpacker.java
+++ b/java/src/main/java/org/msgpack/Unpacker.java
@@ -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.
@@ -453,6 +454,15 @@ public class Unpacker implements Iterable<MessagePackObject> {
}
/**
+ * 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.
* @throws MessageTypeException the first value of the buffer is not a {@code float}.