diff --git a/cpp/test/cases.cc b/cpp/test/cases.cc
index b408876c..eb1286c7 100644
--- a/cpp/test/cases.cc
+++ b/cpp/test/cases.cc
@@ -32,5 +32,7 @@ TEST(cases, format)
EXPECT_TRUE( pac_compact.next(&result_compact) );
EXPECT_EQ(result_compact.get(), result.get());
}
+
+ EXPECT_FALSE( pac_compact.next(&result) );
}
diff --git a/java/pom.xml b/java/pom.xml
index 9b74b4cf..44806d51 100755
--- a/java/pom.xml
+++ b/java/pom.xml
@@ -7,7 +7,7 @@
MessagePack for Java
MessagePack for Java
- http://msgpack.sourceforge.net/
+ http://msgpack.org/
@@ -97,29 +97,24 @@
- msgpack.sourceforge.net
+ msgpack.org
MessagePack Maven2 Repository
- http://msgpack.sourceforge.net/maven2
-
-
- msgpack.sourceforge.net
- MessagePack Maven2 Snapshot Repository
- http://msgpack.sourceforge.net/maven2-snapshot
+ http://msgpack.org/maven2
false
- shell.sourceforge.net
- Repository at sourceforge.net
- scp://shell.sourceforge.net/home/groups/m/ms/msgpack/htdocs/maven2/
+ msgpack.org
+ Repository at msgpack.org
+ file://${project.build.directory}/website/maven2/
true
- shell.sourceforge.net
- Repository Name
- scp://shell.sourceforge.net/home/groups/m/ms/msgpack/htdocs/maven2-snapshot/
+ msgpack.org
+ Repository at msgpack.org
+ file://${project.build.directory}/website/maven2/
diff --git a/java/src/main/java/org/msgpack/BufferedUnpackerImpl.java b/java/src/main/java/org/msgpack/BufferedUnpackerImpl.java
index cc6604d4..5b449c79 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;
@@ -47,7 +47,7 @@ abstract class BufferedUnpackerImpl extends UnpackerImpl {
offset = noffset;
} while(!super.isFinished());
- Object obj = super.getData();
+ MessagePackObject obj = super.getData();
super.reset();
result.done(obj);
@@ -103,7 +103,7 @@ abstract class BufferedUnpackerImpl extends UnpackerImpl {
case 0xcc: // unsigned int 8
more(2);
advance(2);
- return (int)((short)buffer[offset+1] & 0xff);
+ return (int)((short)(buffer[offset-1]) & 0xff);
case 0xcd: // unsigned int 16
more(3);
castBuffer.rewind();
@@ -137,7 +137,7 @@ abstract class BufferedUnpackerImpl extends UnpackerImpl {
case 0xd0: // signed int 8
more(2);
advance(2);
- return (int)buffer[offset+1];
+ return (int)buffer[offset-1];
case 0xd1: // signed int 16
more(3);
castBuffer.rewind();
@@ -178,7 +178,7 @@ abstract class BufferedUnpackerImpl extends UnpackerImpl {
case 0xcc: // unsigned int 8
more(2);
advance(2);
- return (long)((short)buffer[offset+1] & 0xff);
+ return (long)((short)(buffer[offset-1]) & 0xff);
case 0xcd: // unsigned int 16
more(3);
castBuffer.rewind();
@@ -198,8 +198,7 @@ abstract class BufferedUnpackerImpl extends UnpackerImpl {
{
long o = castBuffer.getLong(0);
if(o < 0) {
- // FIXME
- throw new MessageTypeException("uint 64 bigger than 0x7fffffff is not supported");
+ throw new MessageTypeException();
}
advance(9);
return o;
@@ -207,7 +206,7 @@ abstract class BufferedUnpackerImpl extends UnpackerImpl {
case 0xd0: // signed int 8
more(2);
advance(2);
- return (long)buffer[offset+1];
+ return (long)buffer[offset-1];
case 0xd1: // signed int 16
more(3);
castBuffer.rewind();
@@ -231,6 +230,26 @@ abstract class BufferedUnpackerImpl extends UnpackerImpl {
}
}
+ 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);
int b = buffer[offset];
@@ -414,7 +433,7 @@ abstract class BufferedUnpackerImpl extends UnpackerImpl {
return s;
}
- final Object unpackObject() throws IOException {
+ final MessagePackObject unpackObject() throws IOException {
UnpackResult result = new UnpackResult();
if(!next(result)) {
super.reset();
diff --git a/java/src/main/java/org/msgpack/MessageConvertable.java b/java/src/main/java/org/msgpack/MessageConvertable.java
index da251dc1..8acf1f28 100644
--- a/java/src/main/java/org/msgpack/MessageConvertable.java
+++ b/java/src/main/java/org/msgpack/MessageConvertable.java
@@ -18,6 +18,6 @@
package org.msgpack;
public interface MessageConvertable {
- public void messageConvert(Object obj) throws MessageTypeException;
+ public void messageConvert(MessagePackObject obj) throws MessageTypeException;
}
diff --git a/java/src/main/java/org/msgpack/MessagePackObject.java b/java/src/main/java/org/msgpack/MessagePackObject.java
new file mode 100644
index 00000000..2424446f
--- /dev/null
+++ b/java/src/main/java/org/msgpack/MessagePackObject.java
@@ -0,0 +1,136 @@
+//
+// MessagePack for Java
+//
+// Copyright (C) 2009-2010 FURUHASHI Sadayuki
+//
+// Licensed under the Apache License, Version 2.0 (the "License");
+// you may not use this file except in compliance with the License.
+// You may obtain a copy of the License at
+//
+// http://www.apache.org/licenses/LICENSE-2.0
+//
+// Unless required by applicable law or agreed to in writing, software
+// distributed under the License is distributed on an "AS IS" BASIS,
+// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+// See the License for the specific language governing permissions and
+// limitations under the License.
+//
+package org.msgpack;
+
+import java.util.List;
+import java.util.Set;
+import java.util.Map;
+import java.math.BigInteger;
+
+public abstract class MessagePackObject implements Cloneable, MessagePackable {
+ public boolean isNil() {
+ return false;
+ }
+
+ public boolean isBooleanType() {
+ return false;
+ }
+
+ public boolean isIntegerType() {
+ return false;
+ }
+
+ public boolean isFloatType() {
+ return false;
+ }
+
+ public boolean isArrayType() {
+ return false;
+ }
+
+ public boolean isMapType() {
+ return false;
+ }
+
+ public boolean isRawType() {
+ return false;
+ }
+
+ public boolean asBoolean() {
+ throw new MessageTypeException("type error");
+ }
+
+ public byte asByte() {
+ throw new MessageTypeException("type error");
+ }
+
+ public short asShort() {
+ throw new MessageTypeException("type error");
+ }
+
+ public int asInt() {
+ throw new MessageTypeException("type error");
+ }
+
+ public long asLong() {
+ throw new MessageTypeException("type error");
+ }
+
+ public BigInteger asBigInteger() {
+ throw new MessageTypeException("type error");
+ }
+
+ public float asFloat() {
+ throw new MessageTypeException("type error");
+ }
+
+ public double asDouble() {
+ throw new MessageTypeException("type error");
+ }
+
+ public byte[] asByteArray() {
+ throw new MessageTypeException("type error");
+ }
+
+ public String asString() {
+ throw new MessageTypeException("type error");
+ }
+
+ public MessagePackObject[] asArray() {
+ throw new MessageTypeException("type error");
+ }
+
+ public List asList() {
+ throw new MessageTypeException("type error");
+ }
+
+ public Map asMap() {
+ throw new MessageTypeException("type error");
+ }
+
+ public byte byteValue() {
+ throw new MessageTypeException("type error");
+ }
+
+ public short shortValue() {
+ throw new MessageTypeException("type error");
+ }
+
+ public int intValue() {
+ throw new MessageTypeException("type error");
+ }
+
+ public long longValue() {
+ throw new MessageTypeException("type error");
+ }
+
+ public BigInteger bigIntegerValue() {
+ throw new MessageTypeException("type error");
+ }
+
+ public float floatValue() {
+ throw new MessageTypeException("type error");
+ }
+
+ public double doubleValue() {
+ throw new MessageTypeException("type error");
+ }
+
+ abstract public Object clone();
+}
+
diff --git a/java/src/main/java/org/msgpack/MessageTypeException.java b/java/src/main/java/org/msgpack/MessageTypeException.java
index 0fa37b76..698ef6dd 100644
--- a/java/src/main/java/org/msgpack/MessageTypeException.java
+++ b/java/src/main/java/org/msgpack/MessageTypeException.java
@@ -23,15 +23,5 @@ public class MessageTypeException extends RuntimeException {
public MessageTypeException(String s) {
super(s);
}
-
- public static MessageTypeException invalidConvert(Object from, Schema to) {
- return new MessageTypeException(from.getClass().getName()+" cannot be convert to "+to.getExpression());
- }
-
- /* FIXME
- public static MessageTypeException schemaMismatch(Schema to) {
- return new MessageTypeException("schema mismatch "+to.getExpression());
- }
- */
}
diff --git a/java/src/main/java/org/msgpack/Packer.java b/java/src/main/java/org/msgpack/Packer.java
index dd510f34..139b3b15 100644
--- a/java/src/main/java/org/msgpack/Packer.java
+++ b/java/src/main/java/org/msgpack/Packer.java
@@ -22,6 +22,7 @@ import java.io.IOException;
import java.nio.ByteBuffer;
import java.util.List;
import java.util.Map;
+import java.math.BigInteger;
/**
* Packer enables you to serialize objects into OutputStream.
@@ -194,6 +195,27 @@ public class Packer {
return this;
}
+ public Packer packBigInteger(BigInteger d) throws IOException {
+ if(d.bitLength() <= 63) {
+ return packLong(d.longValue());
+ } else if(d.bitLength() <= 64 && d.signum() >= 0) {
+ castBytes[0] = (byte)0xcf;
+ byte[] barray = d.toByteArray();
+ castBytes[1] = barray[barray.length-8];
+ castBytes[2] = barray[barray.length-7];
+ castBytes[3] = barray[barray.length-6];
+ castBytes[4] = barray[barray.length-5];
+ castBytes[5] = barray[barray.length-4];
+ castBytes[6] = barray[barray.length-3];
+ castBytes[7] = barray[barray.length-2];
+ castBytes[8] = barray[barray.length-1];
+ out.write(castBytes);
+ return this;
+ } else {
+ throw new MessageTypeException("can't pack BigInteger larger than 0xffffffffffffffff");
+ }
+ }
+
public Packer packFloat(float d) throws IOException {
castBytes[0] = (byte)0xca;
castBuffer.putFloat(1, d);
@@ -286,12 +308,6 @@ public class Packer {
}
- public Packer packWithSchema(Object o, Schema s) throws IOException {
- s.pack(this, o);
- return this;
- }
-
-
public Packer packString(String s) throws IOException {
byte[] b = ((String)s).getBytes("UTF-8");
packRaw(b.length);
@@ -299,39 +315,36 @@ public class Packer {
}
- public Packer pack(String o) throws IOException {
- if(o == null) { return packNil(); }
- return packString(o);
- }
-
- public Packer pack(MessagePackable o) throws IOException {
- if(o == null) { return packNil(); }
- o.messagePack(this);
- return this;
- }
-
- public Packer pack(byte[] o) throws IOException {
- if(o == null) { return packNil(); }
- packRaw(o.length);
- return packRawBody(o);
- }
-
- public Packer pack(List o) throws IOException {
- if(o == null) { return packNil(); }
- packArray(o.size());
- for(Object i : o) { pack(i); }
- return this;
- }
-
- @SuppressWarnings("unchecked")
- public Packer pack(Map o) throws IOException {
- if(o == null) { return packNil(); }
- packMap(o.size());
- for(Map.Entry e : ((Map