mirror of
https://github.com/msgpack/msgpack-c.git
synced 2025-04-01 01:16:52 +02:00
Merge branch 'master' of git@github.com:msgpack/msgpack
This commit is contained in:
commit
56ad6915d0
@ -1,3 +1,39 @@
|
|||||||
|
|
||||||
|
Release 0.4.2 - 2010/11/09
|
||||||
|
NEW FEATURES
|
||||||
|
Added MessagePackNullable annotation and Tempalte.tNullable(Template)
|
||||||
|
method.
|
||||||
|
|
||||||
|
Added <T> T MessagePackObject.unpack(Class<T>) method.
|
||||||
|
|
||||||
|
|
||||||
|
Release 0.4.1 - 2010/11/05
|
||||||
|
BUG FIXES
|
||||||
|
Fixed dynamic code generation of unpack methods
|
||||||
|
|
||||||
|
|
||||||
|
Release 0.4.0 - 2010/10/25
|
||||||
|
NEW FEATURES
|
||||||
|
Added MessagePackObject class and org.msgpack.object package that
|
||||||
|
represent unpacked (=dynamically typed) objects.
|
||||||
|
Unpacker.unpack method returns MessagePackObject instead of Object.
|
||||||
|
|
||||||
|
Added Templates class and org.msgpack.template package that provide
|
||||||
|
type conversion feature.
|
||||||
|
|
||||||
|
User-defined classes annotated with MessagePackMessage can be
|
||||||
|
pack/unpack/converted.
|
||||||
|
|
||||||
|
User-defined classes registered with MessagePack.register(Class) can be
|
||||||
|
pack/unpack/converted.
|
||||||
|
|
||||||
|
Added dynamic code generation feature for user-defined classes.
|
||||||
|
|
||||||
|
Added MessagePackOptional annotation.
|
||||||
|
|
||||||
|
Added MessagePack class that implements typical useful methods.
|
||||||
|
|
||||||
|
|
||||||
Release 0.3 - 2010/05/23
|
Release 0.3 - 2010/05/23
|
||||||
NEW FEATURES
|
NEW FEATURES
|
||||||
Added Unbuffered API + Direct Conversion API to the Unpacker.
|
Added Unbuffered API + Direct Conversion API to the Unpacker.
|
||||||
|
@ -3,7 +3,7 @@
|
|||||||
<modelVersion>4.0.0</modelVersion>
|
<modelVersion>4.0.0</modelVersion>
|
||||||
<groupId>org.msgpack</groupId>
|
<groupId>org.msgpack</groupId>
|
||||||
<artifactId>msgpack</artifactId>
|
<artifactId>msgpack</artifactId>
|
||||||
<version>0.4.1-devel</version>
|
<version>0.4.2-devel</version>
|
||||||
<description>MessagePack for Java</description>
|
<description>MessagePack for Java</description>
|
||||||
|
|
||||||
<name>MessagePack for Java</name>
|
<name>MessagePack for Java</name>
|
||||||
|
@ -51,7 +51,7 @@ public class MessagePack {
|
|||||||
return out.toByteArray();
|
return out.toByteArray();
|
||||||
}
|
}
|
||||||
|
|
||||||
public static void pack(OutputStream out, Object obj, Template tmpl) throws IOException {
|
public static void pack(OutputStream out, Object obj, Template tmpl) throws IOException, MessageTypeException {
|
||||||
new Packer(out).pack(obj, tmpl);
|
new Packer(out).pack(obj, tmpl);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -86,13 +86,9 @@ public class MessagePack {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public static MessagePackObject unpack(InputStream in) {
|
public static MessagePackObject unpack(InputStream in) throws IOException {
|
||||||
Unpacker pac = new Unpacker(in);
|
Unpacker pac = new Unpacker(in);
|
||||||
try {
|
return pac.unpackObject();
|
||||||
return pac.unpackObject();
|
|
||||||
} catch (IOException e) {
|
|
||||||
throw new RuntimeException(e);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public static Object unpack(InputStream in, Template tmpl) throws IOException, MessageTypeException {
|
public static Object unpack(InputStream in, Template tmpl) throws IOException, MessageTypeException {
|
||||||
|
@ -21,6 +21,8 @@ import java.util.List;
|
|||||||
import java.util.Set;
|
import java.util.Set;
|
||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
import java.math.BigInteger;
|
import java.math.BigInteger;
|
||||||
|
import org.msgpack.template.ClassTemplate;
|
||||||
|
import org.msgpack.template.NullableTemplate;
|
||||||
|
|
||||||
public abstract class MessagePackObject implements Cloneable, MessagePackable {
|
public abstract class MessagePackObject implements Cloneable, MessagePackable {
|
||||||
static {
|
static {
|
||||||
@ -140,5 +142,10 @@ public abstract class MessagePackObject implements Cloneable, MessagePackable {
|
|||||||
public Object convert(Template tmpl) throws MessageTypeException {
|
public Object convert(Template tmpl) throws MessageTypeException {
|
||||||
return tmpl.convert(this);
|
return tmpl.convert(this);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public <T> T convert(Class<T> klass) throws MessageTypeException {
|
||||||
|
// FIXME nullable?
|
||||||
|
return (T)convert(new NullableTemplate(new ClassTemplate(klass)));
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -23,19 +23,16 @@ public class Templates {
|
|||||||
public static void load() { }
|
public static void load() { }
|
||||||
|
|
||||||
|
|
||||||
|
public static Template tNullable(Template elementTemplate) {
|
||||||
|
return new NullableTemplate(elementTemplate);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
public static final Template TAny = AnyTemplate.getInstance();
|
public static final Template TAny = AnyTemplate.getInstance();
|
||||||
public static Template tAny() {
|
public static Template tAny() {
|
||||||
return TAny;
|
return TAny;
|
||||||
}
|
}
|
||||||
|
|
||||||
public static Template tOptional(Template elementTemplate) {
|
|
||||||
return new OptionalTemplate(elementTemplate);
|
|
||||||
}
|
|
||||||
|
|
||||||
public static Template tOptional(Template elementTemplate, Object defaultObject) {
|
|
||||||
return new OptionalTemplate(elementTemplate, defaultObject);
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
public static Template tList(Template elementTemplate) {
|
public static Template tList(Template elementTemplate) {
|
||||||
return new ListTemplate(elementTemplate);
|
return new ListTemplate(elementTemplate);
|
||||||
|
@ -23,6 +23,8 @@ import java.io.IOException;
|
|||||||
import java.util.Iterator;
|
import java.util.Iterator;
|
||||||
import java.nio.ByteBuffer;
|
import java.nio.ByteBuffer;
|
||||||
import java.math.BigInteger;
|
import java.math.BigInteger;
|
||||||
|
import org.msgpack.template.ClassTemplate;
|
||||||
|
import org.msgpack.template.NullableTemplate;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Unpacker enables you to deserialize objects from stream.
|
* Unpacker enables you to deserialize objects from stream.
|
||||||
@ -581,8 +583,8 @@ public class Unpacker implements Iterable<MessagePackObject> {
|
|||||||
}
|
}
|
||||||
|
|
||||||
final public <T> T unpack(Class<T> klass) throws IOException, MessageTypeException {
|
final public <T> T unpack(Class<T> klass) throws IOException, MessageTypeException {
|
||||||
// FIXME optional?
|
// FIXME nullable?
|
||||||
return (T)unpack(Templates.tOptional(Templates.tClass(klass)));
|
return (T)unpack(new NullableTemplate(new ClassTemplate(klass)));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -0,0 +1,28 @@
|
|||||||
|
//
|
||||||
|
// 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.annotation;
|
||||||
|
|
||||||
|
import java.lang.annotation.ElementType;
|
||||||
|
import java.lang.annotation.Retention;
|
||||||
|
import java.lang.annotation.RetentionPolicy;
|
||||||
|
import java.lang.annotation.Target;
|
||||||
|
|
||||||
|
@Target(ElementType.FIELD)
|
||||||
|
@Retention(RetentionPolicy.RUNTIME)
|
||||||
|
public @interface MessagePackNullable {
|
||||||
|
}
|
@ -0,0 +1,60 @@
|
|||||||
|
//
|
||||||
|
// 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.template;
|
||||||
|
|
||||||
|
import java.nio.ByteBuffer;
|
||||||
|
import java.io.IOException;
|
||||||
|
import org.msgpack.*;
|
||||||
|
|
||||||
|
public class ByteBufferTemplate implements Template {
|
||||||
|
private ByteBufferTemplate() { }
|
||||||
|
|
||||||
|
public void pack(Packer pk, Object target) throws IOException {
|
||||||
|
byte[] bytes = byteBufferToByteArray((ByteBuffer)target);
|
||||||
|
pk.packByteArray(bytes);
|
||||||
|
}
|
||||||
|
|
||||||
|
private static byte[] byteBufferToByteArray(ByteBuffer b) {
|
||||||
|
if (b.hasArray() && b.position() == 0 && b.arrayOffset() == 0
|
||||||
|
&& b.remaining() == b.capacity()) {
|
||||||
|
return b.array();
|
||||||
|
} else {
|
||||||
|
int size = b.remaining();
|
||||||
|
byte[] bytes = new byte[size];
|
||||||
|
System.arraycopy(b.array(), b.arrayOffset() + b.position(), bytes, 0, size);
|
||||||
|
return bytes;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public Object unpack(Unpacker pac) throws IOException, MessageTypeException {
|
||||||
|
byte[] bytes = pac.unpackByteArray();
|
||||||
|
return ByteBuffer.wrap(bytes);
|
||||||
|
}
|
||||||
|
|
||||||
|
public Object convert(MessagePackObject from) throws MessageTypeException {
|
||||||
|
byte[] bytes = from.asByteArray();
|
||||||
|
return ByteBuffer.wrap(bytes);
|
||||||
|
}
|
||||||
|
|
||||||
|
static public ByteBufferTemplate getInstance() {
|
||||||
|
return instance;
|
||||||
|
}
|
||||||
|
|
||||||
|
static final ByteBufferTemplate instance = new ByteBufferTemplate();
|
||||||
|
}
|
||||||
|
|
@ -0,0 +1,56 @@
|
|||||||
|
//
|
||||||
|
// 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.template;
|
||||||
|
|
||||||
|
import java.io.IOException;
|
||||||
|
import org.msgpack.*;
|
||||||
|
|
||||||
|
public class NullableTemplate implements Template {
|
||||||
|
private Template elementTemplate;
|
||||||
|
|
||||||
|
public NullableTemplate(Template elementTemplate) {
|
||||||
|
this.elementTemplate = elementTemplate;
|
||||||
|
}
|
||||||
|
|
||||||
|
public Template getElementTemplate() {
|
||||||
|
return elementTemplate;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void pack(Packer pk, Object target) throws IOException {
|
||||||
|
if(target == null) {
|
||||||
|
pk.packNil();
|
||||||
|
} else {
|
||||||
|
elementTemplate.pack(pk, target);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public Object unpack(Unpacker pac) throws IOException, MessageTypeException {
|
||||||
|
if(pac.tryUnpackNull()) {
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
return elementTemplate.unpack(pac);
|
||||||
|
}
|
||||||
|
|
||||||
|
public Object convert(MessagePackObject from) throws MessageTypeException {
|
||||||
|
if(from.isNil()) {
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
return elementTemplate.convert(from);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
@ -39,7 +39,9 @@ import org.msgpack.Packer;
|
|||||||
import org.msgpack.Template;
|
import org.msgpack.Template;
|
||||||
import org.msgpack.Unpacker;
|
import org.msgpack.Unpacker;
|
||||||
import org.msgpack.annotation.MessagePackOptional;
|
import org.msgpack.annotation.MessagePackOptional;
|
||||||
|
import org.msgpack.annotation.MessagePackNullable;
|
||||||
import org.msgpack.template.OptionalTemplate;
|
import org.msgpack.template.OptionalTemplate;
|
||||||
|
import org.msgpack.template.NullableTemplate;
|
||||||
import org.slf4j.Logger;
|
import org.slf4j.Logger;
|
||||||
import org.slf4j.LoggerFactory;
|
import org.slf4j.LoggerFactory;
|
||||||
|
|
||||||
@ -253,7 +255,6 @@ class DynamicCodeGen extends DynamicCodeGenBase implements Constants {
|
|||||||
}
|
}
|
||||||
|
|
||||||
Template createTemplate(Field field) {
|
Template createTemplate(Field field) {
|
||||||
boolean isOptional = isAnnotated(field, MessagePackOptional.class);
|
|
||||||
Class<?> c = field.getType();
|
Class<?> c = field.getType();
|
||||||
Template tmpl = null;
|
Template tmpl = null;
|
||||||
if (List.class.isAssignableFrom(c) || Map.class.isAssignableFrom(c)) {
|
if (List.class.isAssignableFrom(c) || Map.class.isAssignableFrom(c)) {
|
||||||
@ -261,12 +262,15 @@ class DynamicCodeGen extends DynamicCodeGenBase implements Constants {
|
|||||||
} else {
|
} else {
|
||||||
tmpl = createTemplate(c);
|
tmpl = createTemplate(c);
|
||||||
}
|
}
|
||||||
if (isOptional) {
|
if (isAnnotated(field, MessagePackOptional.class)) {
|
||||||
// for pack
|
// @Optional types
|
||||||
return new OptionalTemplate(tmpl);
|
return new OptionalTemplate(tmpl);
|
||||||
} else {
|
|
||||||
return tmpl;
|
|
||||||
}
|
}
|
||||||
|
if (!c.isPrimitive() && isAnnotated(field, MessagePackNullable.class)) {
|
||||||
|
// @Nullable reference types
|
||||||
|
return new NullableTemplate(tmpl);
|
||||||
|
}
|
||||||
|
return tmpl;
|
||||||
}
|
}
|
||||||
|
|
||||||
private boolean isAnnotated(Field field, Class<? extends Annotation> with) {
|
private boolean isAnnotated(Field field, Class<? extends Annotation> with) {
|
||||||
|
150
java/src/test/java/org/msgpack/TestAnnotations.java
Normal file
150
java/src/test/java/org/msgpack/TestAnnotations.java
Normal file
@ -0,0 +1,150 @@
|
|||||||
|
package org.msgpack;
|
||||||
|
|
||||||
|
import org.msgpack.*;
|
||||||
|
import org.msgpack.object.*;
|
||||||
|
import org.msgpack.annotation.*;
|
||||||
|
import static org.msgpack.Templates.*;
|
||||||
|
|
||||||
|
import java.io.*;
|
||||||
|
import java.util.*;
|
||||||
|
import java.math.BigInteger;
|
||||||
|
|
||||||
|
import org.junit.Test;
|
||||||
|
import junit.framework.TestCase;
|
||||||
|
|
||||||
|
public class TestAnnotations extends TestCase {
|
||||||
|
|
||||||
|
@MessagePackMessage
|
||||||
|
public static class MyClassVersion1 {
|
||||||
|
// required field, not nullable.
|
||||||
|
public String name;
|
||||||
|
|
||||||
|
// required and nullable field.
|
||||||
|
@MessagePackNullable
|
||||||
|
public String nickname;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
@MessagePackMessage
|
||||||
|
public static class MyClassVersion2 {
|
||||||
|
public String name;
|
||||||
|
|
||||||
|
@MessagePackNullable
|
||||||
|
public String nickname;
|
||||||
|
|
||||||
|
// adds an optional field on version 2.
|
||||||
|
@MessagePackOptional
|
||||||
|
public int age = -1;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
@MessagePackMessage
|
||||||
|
public static class MyClassVersion3 {
|
||||||
|
public String name;
|
||||||
|
|
||||||
|
@MessagePackNullable
|
||||||
|
public String nickname;
|
||||||
|
|
||||||
|
// adds required fields on version 3, then
|
||||||
|
// this class is NOT compatible with version 1.
|
||||||
|
public int age;
|
||||||
|
|
||||||
|
// optional field is nullable.
|
||||||
|
@MessagePackOptional
|
||||||
|
public String school;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void testBackwardCompatibility() throws Exception {
|
||||||
|
MyClassVersion1 v1 = new MyClassVersion1();
|
||||||
|
v1.name = "Sadayuki Furuhashi";
|
||||||
|
v1.nickname = "frsyuki";
|
||||||
|
|
||||||
|
byte[] bytes = MessagePack.pack(v1);
|
||||||
|
|
||||||
|
MyClassVersion2 v2 = MessagePack.unpack(bytes, MyClassVersion2.class);
|
||||||
|
|
||||||
|
assertEquals(v1.name, v2.name);
|
||||||
|
assertEquals(v1.nickname, v2.nickname);
|
||||||
|
assertEquals(v2.age, -1);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void testForwardCompatibility() throws Exception {
|
||||||
|
MyClassVersion2 v2 = new MyClassVersion2();
|
||||||
|
v2.name = "Sadayuki Furuhashi";
|
||||||
|
v2.nickname = "frsyuki";
|
||||||
|
v2.age = 23;
|
||||||
|
|
||||||
|
byte[] bytes = MessagePack.pack(v2);
|
||||||
|
|
||||||
|
MyClassVersion1 v1 = MessagePack.unpack(bytes, MyClassVersion1.class);
|
||||||
|
|
||||||
|
assertEquals(v2.name, v1.name);
|
||||||
|
assertEquals(v2.nickname, v1.nickname);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void testNullFields01() throws Exception {
|
||||||
|
MyClassVersion1 src = new MyClassVersion1();
|
||||||
|
src.name = "Sadayuki Furuhashi";
|
||||||
|
src.nickname = null;
|
||||||
|
|
||||||
|
byte[] bytes = MessagePack.pack(src);
|
||||||
|
|
||||||
|
MyClassVersion1 dst = MessagePack.unpack(bytes, MyClassVersion1.class);
|
||||||
|
|
||||||
|
assertEquals(dst.name, src.name);
|
||||||
|
assertEquals(dst.nickname, src.nickname);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void testNullFields02() throws Exception {
|
||||||
|
MyClassVersion1 src = new MyClassVersion1();
|
||||||
|
src.name = null;
|
||||||
|
src.nickname = "frsyuki";
|
||||||
|
|
||||||
|
try {
|
||||||
|
byte[] bytes = MessagePack.pack(src);
|
||||||
|
} catch (Exception e) {
|
||||||
|
assertTrue(true);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
assertTrue(false);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void testNullFields03() throws Exception {
|
||||||
|
List<String> src = new ArrayList<String>();
|
||||||
|
src.add(null);
|
||||||
|
src.add("frsyuki");
|
||||||
|
|
||||||
|
byte[] bytes = MessagePack.pack(src);
|
||||||
|
|
||||||
|
try {
|
||||||
|
MyClassVersion1 dst = MessagePack.unpack(bytes, MyClassVersion1.class);
|
||||||
|
} catch (Exception e) {
|
||||||
|
assertTrue(true);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
assertTrue(false);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void testNullFields04() throws Exception {
|
||||||
|
MyClassVersion3 src = new MyClassVersion3();
|
||||||
|
src.name = "Sadayuki Furuhashi";
|
||||||
|
src.nickname = null;
|
||||||
|
src.age = 23;
|
||||||
|
src.school = null;
|
||||||
|
|
||||||
|
byte[] bytes = MessagePack.pack(src);
|
||||||
|
|
||||||
|
MyClassVersion3 dst = MessagePack.unpack(bytes, MyClassVersion3.class);
|
||||||
|
|
||||||
|
assertEquals(dst.name, src.name);
|
||||||
|
assertEquals(dst.nickname, src.nickname);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
@ -75,16 +75,14 @@ public class TestMessagePackStaticMethods extends TestCase {
|
|||||||
{
|
{
|
||||||
Object aobj = MessagePack.unpack(a, TString);
|
Object aobj = MessagePack.unpack(a, TString);
|
||||||
Object bobj = MessagePack.unpack(b, TInteger);
|
Object bobj = MessagePack.unpack(b, TInteger);
|
||||||
Object cobj_any = MessagePack.unpack(c, TAny);
|
Object cobj = MessagePack.unpack(c, tNullable(TAny));
|
||||||
Object cobj_obj = MessagePack.unpack(c, tOptional(TAny));
|
|
||||||
Object dobj = MessagePack.unpack(d, tList(TString));
|
Object dobj = MessagePack.unpack(d, tList(TString));
|
||||||
Object eobj = MessagePack.unpack(e, tClass(ProvidedClass.class));
|
Object eobj = MessagePack.unpack(e, tClass(ProvidedClass.class));
|
||||||
Object fobj = MessagePack.unpack(f, tClass(UserDefinedClass.class));
|
Object fobj = MessagePack.unpack(f, tClass(UserDefinedClass.class));
|
||||||
|
|
||||||
assertEquals(aobj, "msgpack");
|
assertEquals(aobj, "msgpack");
|
||||||
assertEquals(bobj, 1);
|
assertEquals(bobj, 1);
|
||||||
assertEquals(cobj_any, NilType.create());
|
assertEquals(cobj, null);
|
||||||
assertEquals(cobj_obj, null);
|
|
||||||
assertEquals(dobj, createStringList());
|
assertEquals(dobj, createStringList());
|
||||||
assertEquals(eobj, createProvidedClass());
|
assertEquals(eobj, createProvidedClass());
|
||||||
assertEquals(fobj, createUserDefinedClass());
|
assertEquals(fobj, createUserDefinedClass());
|
||||||
@ -94,6 +92,7 @@ public class TestMessagePackStaticMethods extends TestCase {
|
|||||||
String aobj = MessagePack.unpack(a, String.class);
|
String aobj = MessagePack.unpack(a, String.class);
|
||||||
Integer bobj = MessagePack.unpack(b, Integer.class);
|
Integer bobj = MessagePack.unpack(b, Integer.class);
|
||||||
Object cobj = MessagePack.unpack(c, Object.class);
|
Object cobj = MessagePack.unpack(c, Object.class);
|
||||||
|
// Generics are not supported on unpack(Class<?> klass) interface
|
||||||
ProvidedClass eobj = MessagePack.unpack(e, ProvidedClass.class);
|
ProvidedClass eobj = MessagePack.unpack(e, ProvidedClass.class);
|
||||||
UserDefinedClass fobj = MessagePack.unpack(f, UserDefinedClass.class);
|
UserDefinedClass fobj = MessagePack.unpack(f, UserDefinedClass.class);
|
||||||
|
|
||||||
@ -108,38 +107,37 @@ public class TestMessagePackStaticMethods extends TestCase {
|
|||||||
@Test
|
@Test
|
||||||
public void testCheckedPackToStream() throws Exception {
|
public void testCheckedPackToStream() throws Exception {
|
||||||
ByteArrayOutputStream aout = new ByteArrayOutputStream();
|
ByteArrayOutputStream aout = new ByteArrayOutputStream();
|
||||||
MessagePack.pack(aout, "msgpack");
|
|
||||||
ByteArrayOutputStream bout = new ByteArrayOutputStream();
|
ByteArrayOutputStream bout = new ByteArrayOutputStream();
|
||||||
MessagePack.pack(bout, (Object)1);
|
|
||||||
ByteArrayOutputStream cout = new ByteArrayOutputStream();
|
ByteArrayOutputStream cout = new ByteArrayOutputStream();
|
||||||
MessagePack.pack(cout, (Object)null);
|
|
||||||
ByteArrayOutputStream dout = new ByteArrayOutputStream();
|
ByteArrayOutputStream dout = new ByteArrayOutputStream();
|
||||||
MessagePack.pack(dout, createStringList());
|
|
||||||
ByteArrayOutputStream eout = new ByteArrayOutputStream();
|
ByteArrayOutputStream eout = new ByteArrayOutputStream();
|
||||||
MessagePack.pack(eout, createProvidedClass());
|
|
||||||
ByteArrayOutputStream fout = new ByteArrayOutputStream();
|
ByteArrayOutputStream fout = new ByteArrayOutputStream();
|
||||||
|
|
||||||
|
MessagePack.pack(aout, "msgpack");
|
||||||
|
MessagePack.pack(bout, (Object)1);
|
||||||
|
MessagePack.pack(cout, (Object)null);
|
||||||
|
MessagePack.pack(dout, createStringList());
|
||||||
|
MessagePack.pack(eout, createProvidedClass());
|
||||||
MessagePack.pack(fout, createUserDefinedClass());
|
MessagePack.pack(fout, createUserDefinedClass());
|
||||||
|
|
||||||
{
|
{
|
||||||
InputStream ain = new ByteArrayInputStream(aout.toByteArray());
|
InputStream ain = new ByteArrayInputStream(aout.toByteArray());
|
||||||
Object aobj = MessagePack.unpack(ain, TString);
|
|
||||||
InputStream bin = new ByteArrayInputStream(bout.toByteArray());
|
InputStream bin = new ByteArrayInputStream(bout.toByteArray());
|
||||||
Object bobj = MessagePack.unpack(bin, TInteger);
|
InputStream cin = new ByteArrayInputStream(cout.toByteArray());
|
||||||
InputStream cin_any = new ByteArrayInputStream(cout.toByteArray());
|
|
||||||
Object cobj_any = MessagePack.unpack(cin_any, TAny);
|
|
||||||
InputStream cin_obj = new ByteArrayInputStream(cout.toByteArray());
|
|
||||||
Object cobj_obj = MessagePack.unpack(cin_obj, tOptional(TAny));
|
|
||||||
InputStream din = new ByteArrayInputStream(dout.toByteArray());
|
InputStream din = new ByteArrayInputStream(dout.toByteArray());
|
||||||
Object dobj = MessagePack.unpack(din, tList(TString));
|
|
||||||
InputStream ein = new ByteArrayInputStream(eout.toByteArray());
|
InputStream ein = new ByteArrayInputStream(eout.toByteArray());
|
||||||
Object eobj = MessagePack.unpack(ein, tClass(ProvidedClass.class));
|
|
||||||
InputStream fin = new ByteArrayInputStream(fout.toByteArray());
|
InputStream fin = new ByteArrayInputStream(fout.toByteArray());
|
||||||
|
|
||||||
|
Object aobj = MessagePack.unpack(ain, TString);
|
||||||
|
Object bobj = MessagePack.unpack(bin, TInteger);
|
||||||
|
Object cobj = MessagePack.unpack(cin, tNullable(TAny));
|
||||||
|
Object dobj = MessagePack.unpack(din, tList(TString));
|
||||||
|
Object eobj = MessagePack.unpack(ein, tClass(ProvidedClass.class));
|
||||||
Object fobj = MessagePack.unpack(fin, tClass(UserDefinedClass.class));
|
Object fobj = MessagePack.unpack(fin, tClass(UserDefinedClass.class));
|
||||||
|
|
||||||
assertEquals(aobj, "msgpack");
|
assertEquals(aobj, "msgpack");
|
||||||
assertEquals(bobj, 1);
|
assertEquals(bobj, 1);
|
||||||
assertEquals(cobj_any, NilType.create());
|
assertEquals(cobj, null);
|
||||||
assertEquals(cobj_obj, null);
|
|
||||||
assertEquals(dobj, createStringList());
|
assertEquals(dobj, createStringList());
|
||||||
assertEquals(eobj, createProvidedClass());
|
assertEquals(eobj, createProvidedClass());
|
||||||
assertEquals(fobj, createUserDefinedClass());
|
assertEquals(fobj, createUserDefinedClass());
|
||||||
@ -147,14 +145,17 @@ public class TestMessagePackStaticMethods extends TestCase {
|
|||||||
|
|
||||||
{
|
{
|
||||||
InputStream ain = new ByteArrayInputStream(aout.toByteArray());
|
InputStream ain = new ByteArrayInputStream(aout.toByteArray());
|
||||||
String aobj = MessagePack.unpack(ain, String.class);
|
|
||||||
InputStream bin = new ByteArrayInputStream(bout.toByteArray());
|
InputStream bin = new ByteArrayInputStream(bout.toByteArray());
|
||||||
Integer bobj = MessagePack.unpack(bin, Integer.class);
|
|
||||||
InputStream cin = new ByteArrayInputStream(cout.toByteArray());
|
InputStream cin = new ByteArrayInputStream(cout.toByteArray());
|
||||||
Object cobj = MessagePack.unpack(cin, Object.class);
|
|
||||||
InputStream ein = new ByteArrayInputStream(eout.toByteArray());
|
InputStream ein = new ByteArrayInputStream(eout.toByteArray());
|
||||||
ProvidedClass eobj = MessagePack.unpack(ein, ProvidedClass.class);
|
//
|
||||||
InputStream fin = new ByteArrayInputStream(fout.toByteArray());
|
InputStream fin = new ByteArrayInputStream(fout.toByteArray());
|
||||||
|
|
||||||
|
String aobj = MessagePack.unpack(ain, String.class);
|
||||||
|
Integer bobj = MessagePack.unpack(bin, Integer.class);
|
||||||
|
Object cobj = MessagePack.unpack(cin, Object.class);
|
||||||
|
// Generics are not supported on unpack(Class<?> klass) interface
|
||||||
|
ProvidedClass eobj = MessagePack.unpack(ein, ProvidedClass.class);
|
||||||
UserDefinedClass fobj = MessagePack.unpack(fin, UserDefinedClass.class);
|
UserDefinedClass fobj = MessagePack.unpack(fin, UserDefinedClass.class);
|
||||||
|
|
||||||
assertEquals(aobj, "msgpack");
|
assertEquals(aobj, "msgpack");
|
||||||
@ -194,30 +195,32 @@ public class TestMessagePackStaticMethods extends TestCase {
|
|||||||
@Test
|
@Test
|
||||||
public void testPackToStream() throws Exception {
|
public void testPackToStream() throws Exception {
|
||||||
ByteArrayOutputStream aout = new ByteArrayOutputStream();
|
ByteArrayOutputStream aout = new ByteArrayOutputStream();
|
||||||
MessagePack.pack(aout, "msgpack");
|
|
||||||
ByteArrayOutputStream bout = new ByteArrayOutputStream();
|
ByteArrayOutputStream bout = new ByteArrayOutputStream();
|
||||||
MessagePack.pack(bout, (Object)1);
|
|
||||||
ByteArrayOutputStream cout = new ByteArrayOutputStream();
|
ByteArrayOutputStream cout = new ByteArrayOutputStream();
|
||||||
MessagePack.pack(cout, (Object)null);
|
|
||||||
ByteArrayOutputStream dout = new ByteArrayOutputStream();
|
ByteArrayOutputStream dout = new ByteArrayOutputStream();
|
||||||
MessagePack.pack(dout, createStringList());
|
|
||||||
ByteArrayOutputStream eout = new ByteArrayOutputStream();
|
ByteArrayOutputStream eout = new ByteArrayOutputStream();
|
||||||
MessagePack.pack(eout, createProvidedClass());
|
|
||||||
ByteArrayOutputStream fout = new ByteArrayOutputStream();
|
ByteArrayOutputStream fout = new ByteArrayOutputStream();
|
||||||
|
|
||||||
|
MessagePack.pack(aout, "msgpack");
|
||||||
|
MessagePack.pack(bout, (Object)1);
|
||||||
|
MessagePack.pack(cout, (Object)null);
|
||||||
|
MessagePack.pack(dout, createStringList());
|
||||||
|
MessagePack.pack(eout, createProvidedClass());
|
||||||
MessagePack.pack(fout, createUserDefinedClass());
|
MessagePack.pack(fout, createUserDefinedClass());
|
||||||
|
|
||||||
{
|
{
|
||||||
InputStream ain = new ByteArrayInputStream(aout.toByteArray());
|
InputStream ain = new ByteArrayInputStream(aout.toByteArray());
|
||||||
MessagePackObject aobj = MessagePack.unpack(ain);
|
|
||||||
InputStream bin = new ByteArrayInputStream(bout.toByteArray());
|
InputStream bin = new ByteArrayInputStream(bout.toByteArray());
|
||||||
MessagePackObject bobj = MessagePack.unpack(bin);
|
|
||||||
InputStream cin = new ByteArrayInputStream(cout.toByteArray());
|
InputStream cin = new ByteArrayInputStream(cout.toByteArray());
|
||||||
MessagePackObject cobj = MessagePack.unpack(cin);
|
|
||||||
InputStream din = new ByteArrayInputStream(dout.toByteArray());
|
InputStream din = new ByteArrayInputStream(dout.toByteArray());
|
||||||
MessagePackObject dobj = MessagePack.unpack(din);
|
|
||||||
InputStream ein = new ByteArrayInputStream(eout.toByteArray());
|
InputStream ein = new ByteArrayInputStream(eout.toByteArray());
|
||||||
MessagePackObject eobj = MessagePack.unpack(ein);
|
|
||||||
InputStream fin = new ByteArrayInputStream(fout.toByteArray());
|
InputStream fin = new ByteArrayInputStream(fout.toByteArray());
|
||||||
|
|
||||||
|
MessagePackObject aobj = MessagePack.unpack(ain);
|
||||||
|
MessagePackObject bobj = MessagePack.unpack(bin);
|
||||||
|
MessagePackObject cobj = MessagePack.unpack(cin);
|
||||||
|
MessagePackObject dobj = MessagePack.unpack(din);
|
||||||
|
MessagePackObject eobj = MessagePack.unpack(ein);
|
||||||
MessagePackObject fobj = MessagePack.unpack(fin);
|
MessagePackObject fobj = MessagePack.unpack(fin);
|
||||||
|
|
||||||
assertEquals(aobj, RawType.create("msgpack"));
|
assertEquals(aobj, RawType.create("msgpack"));
|
||||||
|
@ -20,7 +20,7 @@ import org.msgpack.template.DoubleTemplate;
|
|||||||
import org.msgpack.template.FloatTemplate;
|
import org.msgpack.template.FloatTemplate;
|
||||||
import org.msgpack.template.IntegerTemplate;
|
import org.msgpack.template.IntegerTemplate;
|
||||||
import org.msgpack.template.LongTemplate;
|
import org.msgpack.template.LongTemplate;
|
||||||
import org.msgpack.template.OptionalTemplate;
|
import org.msgpack.template.NullableTemplate;
|
||||||
import org.msgpack.template.ShortTemplate;
|
import org.msgpack.template.ShortTemplate;
|
||||||
import org.msgpack.template.StringTemplate;
|
import org.msgpack.template.StringTemplate;
|
||||||
|
|
||||||
@ -64,7 +64,7 @@ public class TestPackConvert extends TestCase {
|
|||||||
assertTrue(e instanceof MessageTypeException);
|
assertTrue(e instanceof MessageTypeException);
|
||||||
}
|
}
|
||||||
obj = Util.unpackOne(out.toByteArray());
|
obj = Util.unpackOne(out.toByteArray());
|
||||||
tmpl = new OptionalTemplate(ByteTemplate.getInstance());
|
tmpl = new NullableTemplate(ByteTemplate.getInstance());
|
||||||
dst = (Byte) tmpl.convert(obj);
|
dst = (Byte) tmpl.convert(obj);
|
||||||
assertEquals(src, dst);
|
assertEquals(src, dst);
|
||||||
}
|
}
|
||||||
@ -107,7 +107,7 @@ public class TestPackConvert extends TestCase {
|
|||||||
assertTrue(e instanceof MessageTypeException);
|
assertTrue(e instanceof MessageTypeException);
|
||||||
}
|
}
|
||||||
obj = Util.unpackOne(out.toByteArray());
|
obj = Util.unpackOne(out.toByteArray());
|
||||||
tmpl = new OptionalTemplate(ShortTemplate.getInstance());
|
tmpl = new NullableTemplate(ShortTemplate.getInstance());
|
||||||
dst = (Short) tmpl.convert(obj);
|
dst = (Short) tmpl.convert(obj);
|
||||||
assertEquals(src, dst);
|
assertEquals(src, dst);
|
||||||
}
|
}
|
||||||
@ -150,7 +150,7 @@ public class TestPackConvert extends TestCase {
|
|||||||
assertTrue(e instanceof MessageTypeException);
|
assertTrue(e instanceof MessageTypeException);
|
||||||
}
|
}
|
||||||
obj = Util.unpackOne(out.toByteArray());
|
obj = Util.unpackOne(out.toByteArray());
|
||||||
tmpl = new OptionalTemplate(IntegerTemplate.getInstance());
|
tmpl = new NullableTemplate(IntegerTemplate.getInstance());
|
||||||
dst = (Integer) tmpl.convert(obj);
|
dst = (Integer) tmpl.convert(obj);
|
||||||
assertEquals(src, dst);
|
assertEquals(src, dst);
|
||||||
}
|
}
|
||||||
@ -195,7 +195,7 @@ public class TestPackConvert extends TestCase {
|
|||||||
assertTrue(e instanceof MessageTypeException);
|
assertTrue(e instanceof MessageTypeException);
|
||||||
}
|
}
|
||||||
obj = Util.unpackOne(out.toByteArray());
|
obj = Util.unpackOne(out.toByteArray());
|
||||||
tmpl = new OptionalTemplate(LongTemplate.getInstance());
|
tmpl = new NullableTemplate(LongTemplate.getInstance());
|
||||||
dst = (Long) tmpl.convert(obj);
|
dst = (Long) tmpl.convert(obj);
|
||||||
assertEquals(src, dst);
|
assertEquals(src, dst);
|
||||||
}
|
}
|
||||||
@ -244,7 +244,7 @@ public class TestPackConvert extends TestCase {
|
|||||||
assertTrue(e instanceof MessageTypeException);
|
assertTrue(e instanceof MessageTypeException);
|
||||||
}
|
}
|
||||||
obj = Util.unpackOne(out.toByteArray());
|
obj = Util.unpackOne(out.toByteArray());
|
||||||
tmpl = new OptionalTemplate(BigIntegerTemplate.getInstance());
|
tmpl = new NullableTemplate(BigIntegerTemplate.getInstance());
|
||||||
dst = (BigInteger) tmpl.convert(obj);
|
dst = (BigInteger) tmpl.convert(obj);
|
||||||
assertEquals(src, dst);
|
assertEquals(src, dst);
|
||||||
}
|
}
|
||||||
@ -291,7 +291,7 @@ public class TestPackConvert extends TestCase {
|
|||||||
assertTrue(e instanceof MessageTypeException);
|
assertTrue(e instanceof MessageTypeException);
|
||||||
}
|
}
|
||||||
obj = Util.unpackOne(out.toByteArray());
|
obj = Util.unpackOne(out.toByteArray());
|
||||||
tmpl = new OptionalTemplate(FloatTemplate.getInstance());
|
tmpl = new NullableTemplate(FloatTemplate.getInstance());
|
||||||
dst = (Float) tmpl.convert(obj);
|
dst = (Float) tmpl.convert(obj);
|
||||||
assertEquals(src, dst);
|
assertEquals(src, dst);
|
||||||
}
|
}
|
||||||
@ -337,7 +337,7 @@ public class TestPackConvert extends TestCase {
|
|||||||
assertTrue(e instanceof MessageTypeException);
|
assertTrue(e instanceof MessageTypeException);
|
||||||
}
|
}
|
||||||
obj = Util.unpackOne(out.toByteArray());
|
obj = Util.unpackOne(out.toByteArray());
|
||||||
tmpl = new OptionalTemplate(DoubleTemplate.getInstance());
|
tmpl = new NullableTemplate(DoubleTemplate.getInstance());
|
||||||
dst = (Double) tmpl.convert(obj);
|
dst = (Double) tmpl.convert(obj);
|
||||||
assertEquals(src, dst);
|
assertEquals(src, dst);
|
||||||
}
|
}
|
||||||
@ -373,7 +373,7 @@ public class TestPackConvert extends TestCase {
|
|||||||
assertTrue(e instanceof MessageTypeException);
|
assertTrue(e instanceof MessageTypeException);
|
||||||
}
|
}
|
||||||
obj = Util.unpackOne(out.toByteArray());
|
obj = Util.unpackOne(out.toByteArray());
|
||||||
tmpl = new OptionalTemplate(BooleanTemplate.getInstance());
|
tmpl = new NullableTemplate(BooleanTemplate.getInstance());
|
||||||
dst = (Boolean) tmpl.convert(obj);
|
dst = (Boolean) tmpl.convert(obj);
|
||||||
assertEquals(src, dst);
|
assertEquals(src, dst);
|
||||||
}
|
}
|
||||||
@ -441,7 +441,7 @@ public class TestPackConvert extends TestCase {
|
|||||||
assertTrue(e instanceof MessageTypeException);
|
assertTrue(e instanceof MessageTypeException);
|
||||||
}
|
}
|
||||||
obj = Util.unpackOne(out.toByteArray());
|
obj = Util.unpackOne(out.toByteArray());
|
||||||
tmpl = new OptionalTemplate(StringTemplate.getInstance());
|
tmpl = new NullableTemplate(StringTemplate.getInstance());
|
||||||
dst = (String) tmpl.convert(obj);
|
dst = (String) tmpl.convert(obj);
|
||||||
assertEquals(src, dst);
|
assertEquals(src, dst);
|
||||||
}
|
}
|
||||||
|
@ -20,7 +20,7 @@ import org.msgpack.template.DoubleTemplate;
|
|||||||
import org.msgpack.template.FloatTemplate;
|
import org.msgpack.template.FloatTemplate;
|
||||||
import org.msgpack.template.IntegerTemplate;
|
import org.msgpack.template.IntegerTemplate;
|
||||||
import org.msgpack.template.LongTemplate;
|
import org.msgpack.template.LongTemplate;
|
||||||
import org.msgpack.template.OptionalTemplate;
|
import org.msgpack.template.NullableTemplate;
|
||||||
import org.msgpack.template.ShortTemplate;
|
import org.msgpack.template.ShortTemplate;
|
||||||
import org.msgpack.template.StringTemplate;
|
import org.msgpack.template.StringTemplate;
|
||||||
|
|
||||||
@ -67,7 +67,7 @@ public class TestPackUnpack extends TestCase {
|
|||||||
assertTrue(e instanceof MessageTypeException);
|
assertTrue(e instanceof MessageTypeException);
|
||||||
}
|
}
|
||||||
unpacker.wrap(bytes);
|
unpacker.wrap(bytes);
|
||||||
tmpl = new OptionalTemplate(ByteTemplate.getInstance());
|
tmpl = new NullableTemplate(ByteTemplate.getInstance());
|
||||||
dst = (Byte) tmpl.unpack(unpacker);
|
dst = (Byte) tmpl.unpack(unpacker);
|
||||||
assertEquals(src, dst);
|
assertEquals(src, dst);
|
||||||
}
|
}
|
||||||
@ -113,7 +113,7 @@ public class TestPackUnpack extends TestCase {
|
|||||||
assertTrue(e instanceof MessageTypeException);
|
assertTrue(e instanceof MessageTypeException);
|
||||||
}
|
}
|
||||||
unpacker.wrap(bytes);
|
unpacker.wrap(bytes);
|
||||||
tmpl = new OptionalTemplate(ShortTemplate.getInstance());
|
tmpl = new NullableTemplate(ShortTemplate.getInstance());
|
||||||
dst = (Short) tmpl.unpack(unpacker);
|
dst = (Short) tmpl.unpack(unpacker);
|
||||||
assertEquals(src, dst);
|
assertEquals(src, dst);
|
||||||
}
|
}
|
||||||
@ -159,7 +159,7 @@ public class TestPackUnpack extends TestCase {
|
|||||||
assertTrue(e instanceof MessageTypeException);
|
assertTrue(e instanceof MessageTypeException);
|
||||||
}
|
}
|
||||||
unpacker.wrap(bytes);
|
unpacker.wrap(bytes);
|
||||||
tmpl = new OptionalTemplate(IntegerTemplate.getInstance());
|
tmpl = new NullableTemplate(IntegerTemplate.getInstance());
|
||||||
dst = (Integer) tmpl.unpack(unpacker);
|
dst = (Integer) tmpl.unpack(unpacker);
|
||||||
assertEquals(src, dst);
|
assertEquals(src, dst);
|
||||||
}
|
}
|
||||||
@ -207,7 +207,7 @@ public class TestPackUnpack extends TestCase {
|
|||||||
assertTrue(e instanceof MessageTypeException);
|
assertTrue(e instanceof MessageTypeException);
|
||||||
}
|
}
|
||||||
unpacker.wrap(bytes);
|
unpacker.wrap(bytes);
|
||||||
tmpl = new OptionalTemplate(LongTemplate.getInstance());
|
tmpl = new NullableTemplate(LongTemplate.getInstance());
|
||||||
dst = (Long) tmpl.unpack(unpacker);
|
dst = (Long) tmpl.unpack(unpacker);
|
||||||
assertEquals(src, dst);
|
assertEquals(src, dst);
|
||||||
}
|
}
|
||||||
@ -259,7 +259,7 @@ public class TestPackUnpack extends TestCase {
|
|||||||
assertTrue(e instanceof MessageTypeException);
|
assertTrue(e instanceof MessageTypeException);
|
||||||
}
|
}
|
||||||
unpacker.wrap(bytes);
|
unpacker.wrap(bytes);
|
||||||
tmpl = new OptionalTemplate(BigIntegerTemplate.getInstance());
|
tmpl = new NullableTemplate(BigIntegerTemplate.getInstance());
|
||||||
dst = (BigInteger) tmpl.unpack(unpacker);
|
dst = (BigInteger) tmpl.unpack(unpacker);
|
||||||
assertEquals(src, dst);
|
assertEquals(src, dst);
|
||||||
}
|
}
|
||||||
@ -309,7 +309,7 @@ public class TestPackUnpack extends TestCase {
|
|||||||
assertTrue(e instanceof MessageTypeException);
|
assertTrue(e instanceof MessageTypeException);
|
||||||
}
|
}
|
||||||
unpacker.wrap(bytes);
|
unpacker.wrap(bytes);
|
||||||
tmpl = new OptionalTemplate(FloatTemplate.getInstance());
|
tmpl = new NullableTemplate(FloatTemplate.getInstance());
|
||||||
dst = (Float) tmpl.unpack(unpacker);
|
dst = (Float) tmpl.unpack(unpacker);
|
||||||
assertEquals(src, dst);
|
assertEquals(src, dst);
|
||||||
}
|
}
|
||||||
@ -358,7 +358,7 @@ public class TestPackUnpack extends TestCase {
|
|||||||
assertTrue(e instanceof MessageTypeException);
|
assertTrue(e instanceof MessageTypeException);
|
||||||
}
|
}
|
||||||
unpacker.wrap(bytes);
|
unpacker.wrap(bytes);
|
||||||
tmpl = new OptionalTemplate(DoubleTemplate.getInstance());
|
tmpl = new NullableTemplate(DoubleTemplate.getInstance());
|
||||||
dst = (Double) tmpl.unpack(unpacker);
|
dst = (Double) tmpl.unpack(unpacker);
|
||||||
assertEquals(src, dst);
|
assertEquals(src, dst);
|
||||||
}
|
}
|
||||||
@ -397,7 +397,7 @@ public class TestPackUnpack extends TestCase {
|
|||||||
assertTrue(e instanceof MessageTypeException);
|
assertTrue(e instanceof MessageTypeException);
|
||||||
}
|
}
|
||||||
unpacker.wrap(bytes);
|
unpacker.wrap(bytes);
|
||||||
tmpl = new OptionalTemplate(BooleanTemplate.getInstance());
|
tmpl = new NullableTemplate(BooleanTemplate.getInstance());
|
||||||
dst = (Boolean) tmpl.unpack(unpacker);
|
dst = (Boolean) tmpl.unpack(unpacker);
|
||||||
assertEquals(src, dst);
|
assertEquals(src, dst);
|
||||||
}
|
}
|
||||||
@ -468,7 +468,7 @@ public class TestPackUnpack extends TestCase {
|
|||||||
assertTrue(e instanceof MessageTypeException);
|
assertTrue(e instanceof MessageTypeException);
|
||||||
}
|
}
|
||||||
unpacker.wrap(bytes);
|
unpacker.wrap(bytes);
|
||||||
tmpl = new OptionalTemplate(StringTemplate.getInstance());
|
tmpl = new NullableTemplate(StringTemplate.getInstance());
|
||||||
dst = (String) tmpl.unpack(unpacker);
|
dst = (String) tmpl.unpack(unpacker);
|
||||||
assertEquals(src, dst);
|
assertEquals(src, dst);
|
||||||
}
|
}
|
||||||
|
@ -56,7 +56,7 @@ public class TestPackConvert extends TestCase {
|
|||||||
assertTrue(e instanceof MessageTypeException);
|
assertTrue(e instanceof MessageTypeException);
|
||||||
}
|
}
|
||||||
obj = Util.unpackOne(out.toByteArray());
|
obj = Util.unpackOne(out.toByteArray());
|
||||||
tmpl = new OptionalTemplate(IntegerTemplate.getInstance());
|
tmpl = new NullableTemplate(IntegerTemplate.getInstance());
|
||||||
dst = (Integer) tmpl.convert(obj);
|
dst = (Integer) tmpl.convert(obj);
|
||||||
assertEquals(src, dst);
|
assertEquals(src, dst);
|
||||||
}
|
}
|
||||||
@ -100,7 +100,7 @@ public class TestPackConvert extends TestCase {
|
|||||||
assertTrue(e instanceof MessageTypeException);
|
assertTrue(e instanceof MessageTypeException);
|
||||||
}
|
}
|
||||||
obj = Util.unpackOne(out.toByteArray());
|
obj = Util.unpackOne(out.toByteArray());
|
||||||
tmpl = new OptionalTemplate(LongTemplate.getInstance());
|
tmpl = new NullableTemplate(LongTemplate.getInstance());
|
||||||
dst = (Long) tmpl.convert(obj);
|
dst = (Long) tmpl.convert(obj);
|
||||||
assertEquals(src, dst);
|
assertEquals(src, dst);
|
||||||
}
|
}
|
||||||
@ -147,7 +147,7 @@ public class TestPackConvert extends TestCase {
|
|||||||
assertTrue(e instanceof MessageTypeException);
|
assertTrue(e instanceof MessageTypeException);
|
||||||
}
|
}
|
||||||
obj = Util.unpackOne(out.toByteArray());
|
obj = Util.unpackOne(out.toByteArray());
|
||||||
tmpl = new OptionalTemplate(BigIntegerTemplate.getInstance());
|
tmpl = new NullableTemplate(BigIntegerTemplate.getInstance());
|
||||||
dst = (BigInteger) tmpl.convert(obj);
|
dst = (BigInteger) tmpl.convert(obj);
|
||||||
assertEquals(src, dst);
|
assertEquals(src, dst);
|
||||||
}
|
}
|
||||||
@ -193,7 +193,7 @@ public class TestPackConvert extends TestCase {
|
|||||||
assertTrue(e instanceof MessageTypeException);
|
assertTrue(e instanceof MessageTypeException);
|
||||||
}
|
}
|
||||||
obj = Util.unpackOne(out.toByteArray());
|
obj = Util.unpackOne(out.toByteArray());
|
||||||
tmpl = new OptionalTemplate(FloatTemplate.getInstance());
|
tmpl = new NullableTemplate(FloatTemplate.getInstance());
|
||||||
dst = (Float) tmpl.convert(obj);
|
dst = (Float) tmpl.convert(obj);
|
||||||
assertEquals(src, dst);
|
assertEquals(src, dst);
|
||||||
}
|
}
|
||||||
@ -239,7 +239,7 @@ public class TestPackConvert extends TestCase {
|
|||||||
assertTrue(e instanceof MessageTypeException);
|
assertTrue(e instanceof MessageTypeException);
|
||||||
}
|
}
|
||||||
obj = Util.unpackOne(out.toByteArray());
|
obj = Util.unpackOne(out.toByteArray());
|
||||||
tmpl = new OptionalTemplate(DoubleTemplate.getInstance());
|
tmpl = new NullableTemplate(DoubleTemplate.getInstance());
|
||||||
dst = (Double) tmpl.convert(obj);
|
dst = (Double) tmpl.convert(obj);
|
||||||
assertEquals(src, dst);
|
assertEquals(src, dst);
|
||||||
}
|
}
|
||||||
@ -274,7 +274,7 @@ public class TestPackConvert extends TestCase {
|
|||||||
assertTrue(e instanceof MessageTypeException);
|
assertTrue(e instanceof MessageTypeException);
|
||||||
}
|
}
|
||||||
obj = Util.unpackOne(out.toByteArray());
|
obj = Util.unpackOne(out.toByteArray());
|
||||||
tmpl = new OptionalTemplate(BooleanTemplate.getInstance());
|
tmpl = new NullableTemplate(BooleanTemplate.getInstance());
|
||||||
dst = (Boolean) tmpl.convert(obj);
|
dst = (Boolean) tmpl.convert(obj);
|
||||||
assertEquals(src, dst);
|
assertEquals(src, dst);
|
||||||
}
|
}
|
||||||
@ -341,7 +341,7 @@ public class TestPackConvert extends TestCase {
|
|||||||
assertTrue(e instanceof MessageTypeException);
|
assertTrue(e instanceof MessageTypeException);
|
||||||
}
|
}
|
||||||
obj = Util.unpackOne(out.toByteArray());
|
obj = Util.unpackOne(out.toByteArray());
|
||||||
tmpl = new OptionalTemplate(StringTemplate.getInstance());
|
tmpl = new NullableTemplate(StringTemplate.getInstance());
|
||||||
dst = (String) tmpl.convert(obj);
|
dst = (String) tmpl.convert(obj);
|
||||||
assertEquals(src, dst);
|
assertEquals(src, dst);
|
||||||
}
|
}
|
||||||
@ -410,7 +410,7 @@ public class TestPackConvert extends TestCase {
|
|||||||
assertTrue(e instanceof MessageTypeException);
|
assertTrue(e instanceof MessageTypeException);
|
||||||
}
|
}
|
||||||
obj = Util.unpackOne(out.toByteArray());
|
obj = Util.unpackOne(out.toByteArray());
|
||||||
tmpl = new OptionalTemplate(new ListTemplate(StringTemplate
|
tmpl = new NullableTemplate(new ListTemplate(StringTemplate
|
||||||
.getInstance()));
|
.getInstance()));
|
||||||
dst = (List<String>) tmpl.convert(obj);
|
dst = (List<String>) tmpl.convert(obj);
|
||||||
assertEquals(src, dst);
|
assertEquals(src, dst);
|
||||||
@ -489,7 +489,7 @@ public class TestPackConvert extends TestCase {
|
|||||||
assertTrue(e instanceof MessageTypeException);
|
assertTrue(e instanceof MessageTypeException);
|
||||||
}
|
}
|
||||||
obj = Util.unpackOne(out.toByteArray());
|
obj = Util.unpackOne(out.toByteArray());
|
||||||
tmpl = new OptionalTemplate(new MapTemplate(StringTemplate
|
tmpl = new NullableTemplate(new MapTemplate(StringTemplate
|
||||||
.getInstance(), StringTemplate.getInstance()));
|
.getInstance(), StringTemplate.getInstance()));
|
||||||
dst = (Map<String, String>) tmpl.convert(obj);
|
dst = (Map<String, String>) tmpl.convert(obj);
|
||||||
assertEquals(src, dst);
|
assertEquals(src, dst);
|
||||||
|
@ -58,7 +58,7 @@ public class TestPackUnpack extends TestCase {
|
|||||||
assertTrue(e instanceof MessageTypeException);
|
assertTrue(e instanceof MessageTypeException);
|
||||||
}
|
}
|
||||||
unpacker.wrap(bytes);
|
unpacker.wrap(bytes);
|
||||||
tmpl = new OptionalTemplate(IntegerTemplate.getInstance());
|
tmpl = new NullableTemplate(IntegerTemplate.getInstance());
|
||||||
dst = (Integer) tmpl.unpack(unpacker);
|
dst = (Integer) tmpl.unpack(unpacker);
|
||||||
assertEquals(src, dst);
|
assertEquals(src, dst);
|
||||||
}
|
}
|
||||||
@ -105,7 +105,7 @@ public class TestPackUnpack extends TestCase {
|
|||||||
assertTrue(e instanceof MessageTypeException);
|
assertTrue(e instanceof MessageTypeException);
|
||||||
}
|
}
|
||||||
unpacker.wrap(bytes);
|
unpacker.wrap(bytes);
|
||||||
tmpl = new OptionalTemplate(LongTemplate.getInstance());
|
tmpl = new NullableTemplate(LongTemplate.getInstance());
|
||||||
dst = (Long) tmpl.unpack(unpacker);
|
dst = (Long) tmpl.unpack(unpacker);
|
||||||
assertEquals(src, dst);
|
assertEquals(src, dst);
|
||||||
}
|
}
|
||||||
@ -155,7 +155,7 @@ public class TestPackUnpack extends TestCase {
|
|||||||
assertTrue(e instanceof MessageTypeException);
|
assertTrue(e instanceof MessageTypeException);
|
||||||
}
|
}
|
||||||
unpacker.wrap(bytes);
|
unpacker.wrap(bytes);
|
||||||
tmpl = new OptionalTemplate(BigIntegerTemplate.getInstance());
|
tmpl = new NullableTemplate(BigIntegerTemplate.getInstance());
|
||||||
dst = (BigInteger) tmpl.unpack(unpacker);
|
dst = (BigInteger) tmpl.unpack(unpacker);
|
||||||
assertEquals(src, dst);
|
assertEquals(src, dst);
|
||||||
}
|
}
|
||||||
@ -230,7 +230,7 @@ public class TestPackUnpack extends TestCase {
|
|||||||
assertTrue(e instanceof MessageTypeException);
|
assertTrue(e instanceof MessageTypeException);
|
||||||
}
|
}
|
||||||
unpacker.wrap(bytes);
|
unpacker.wrap(bytes);
|
||||||
tmpl = new OptionalTemplate(DoubleTemplate.getInstance());
|
tmpl = new NullableTemplate(DoubleTemplate.getInstance());
|
||||||
dst = (Double) tmpl.unpack(unpacker);
|
dst = (Double) tmpl.unpack(unpacker);
|
||||||
assertEquals(src, dst);
|
assertEquals(src, dst);
|
||||||
}
|
}
|
||||||
@ -268,7 +268,7 @@ public class TestPackUnpack extends TestCase {
|
|||||||
assertTrue(e instanceof MessageTypeException);
|
assertTrue(e instanceof MessageTypeException);
|
||||||
}
|
}
|
||||||
unpacker.wrap(bytes);
|
unpacker.wrap(bytes);
|
||||||
tmpl = new OptionalTemplate(BooleanTemplate.getInstance());
|
tmpl = new NullableTemplate(BooleanTemplate.getInstance());
|
||||||
dst = (Boolean) tmpl.unpack(unpacker);
|
dst = (Boolean) tmpl.unpack(unpacker);
|
||||||
assertEquals(src, dst);
|
assertEquals(src, dst);
|
||||||
}
|
}
|
||||||
@ -338,7 +338,7 @@ public class TestPackUnpack extends TestCase {
|
|||||||
assertTrue(e instanceof MessageTypeException);
|
assertTrue(e instanceof MessageTypeException);
|
||||||
}
|
}
|
||||||
unpacker.wrap(bytes);
|
unpacker.wrap(bytes);
|
||||||
tmpl = new OptionalTemplate(StringTemplate.getInstance());
|
tmpl = new NullableTemplate(StringTemplate.getInstance());
|
||||||
dst = (String) tmpl.unpack(unpacker);
|
dst = (String) tmpl.unpack(unpacker);
|
||||||
assertEquals(src, dst);
|
assertEquals(src, dst);
|
||||||
}
|
}
|
||||||
@ -412,7 +412,7 @@ public class TestPackUnpack extends TestCase {
|
|||||||
assertTrue(e instanceof MessageTypeException);
|
assertTrue(e instanceof MessageTypeException);
|
||||||
}
|
}
|
||||||
unpacker.wrap(bytes);
|
unpacker.wrap(bytes);
|
||||||
tmpl = new OptionalTemplate(new ListTemplate(StringTemplate
|
tmpl = new NullableTemplate(new ListTemplate(StringTemplate
|
||||||
.getInstance()));
|
.getInstance()));
|
||||||
dst = (List<String>) tmpl.unpack(unpacker);
|
dst = (List<String>) tmpl.unpack(unpacker);
|
||||||
assertEquals(src, dst);
|
assertEquals(src, dst);
|
||||||
@ -499,7 +499,7 @@ public class TestPackUnpack extends TestCase {
|
|||||||
assertTrue(e instanceof MessageTypeException);
|
assertTrue(e instanceof MessageTypeException);
|
||||||
}
|
}
|
||||||
unpacker.wrap(bytes);
|
unpacker.wrap(bytes);
|
||||||
tmpl = new OptionalTemplate(new MapTemplate(StringTemplate
|
tmpl = new NullableTemplate(new MapTemplate(StringTemplate
|
||||||
.getInstance(), StringTemplate.getInstance()));
|
.getInstance(), StringTemplate.getInstance()));
|
||||||
dst = (Map<String, String>) tmpl.unpack(unpacker);
|
dst = (Map<String, String>) tmpl.unpack(unpacker);
|
||||||
assertEquals(src, dst);
|
assertEquals(src, dst);
|
||||||
|
@ -30,7 +30,7 @@ import org.msgpack.annotation.MessagePackMessage;
|
|||||||
import org.msgpack.annotation.MessagePackOptional;
|
import org.msgpack.annotation.MessagePackOptional;
|
||||||
import org.msgpack.annotation.MessagePackOrdinalEnum;
|
import org.msgpack.annotation.MessagePackOrdinalEnum;
|
||||||
import org.msgpack.packer.OptionalPacker;
|
import org.msgpack.packer.OptionalPacker;
|
||||||
import org.msgpack.template.OptionalTemplate;
|
import org.msgpack.template.NullableTemplate;
|
||||||
|
|
||||||
public class TestPackConvert extends TestCase {
|
public class TestPackConvert extends TestCase {
|
||||||
|
|
||||||
@ -74,7 +74,7 @@ public class TestPackConvert extends TestCase {
|
|||||||
.create(PrimitiveTypeFieldsClass.class));
|
.create(PrimitiveTypeFieldsClass.class));
|
||||||
packer.pack(new Packer(out), src);
|
packer.pack(new Packer(out), src);
|
||||||
ByteArrayInputStream in = new ByteArrayInputStream(out.toByteArray());
|
ByteArrayInputStream in = new ByteArrayInputStream(out.toByteArray());
|
||||||
Template tmpl = new OptionalTemplate(DynamicTemplate
|
Template tmpl = new NullableTemplate(DynamicTemplate
|
||||||
.create(PrimitiveTypeFieldsClass.class));
|
.create(PrimitiveTypeFieldsClass.class));
|
||||||
Unpacker pac = new Unpacker(in);
|
Unpacker pac = new Unpacker(in);
|
||||||
Iterator<MessagePackObject> it = pac.iterator();
|
Iterator<MessagePackObject> it = pac.iterator();
|
||||||
@ -166,7 +166,7 @@ public class TestPackConvert extends TestCase {
|
|||||||
.create(OptionalPrimitiveTypeFieldsClass.class));
|
.create(OptionalPrimitiveTypeFieldsClass.class));
|
||||||
packer.pack(new Packer(out), src);
|
packer.pack(new Packer(out), src);
|
||||||
ByteArrayInputStream in = new ByteArrayInputStream(out.toByteArray());
|
ByteArrayInputStream in = new ByteArrayInputStream(out.toByteArray());
|
||||||
Template tmpl = new OptionalTemplate(DynamicTemplate
|
Template tmpl = new NullableTemplate(DynamicTemplate
|
||||||
.create(OptionalPrimitiveTypeFieldsClass.class));
|
.create(OptionalPrimitiveTypeFieldsClass.class));
|
||||||
Unpacker pac = new Unpacker(in);
|
Unpacker pac = new Unpacker(in);
|
||||||
Iterator<MessagePackObject> it = pac.iterator();
|
Iterator<MessagePackObject> it = pac.iterator();
|
||||||
@ -248,7 +248,7 @@ public class TestPackConvert extends TestCase {
|
|||||||
.create(GeneralReferenceTypeFieldsClass.class));
|
.create(GeneralReferenceTypeFieldsClass.class));
|
||||||
packer.pack(new Packer(out), src);
|
packer.pack(new Packer(out), src);
|
||||||
ByteArrayInputStream in = new ByteArrayInputStream(out.toByteArray());
|
ByteArrayInputStream in = new ByteArrayInputStream(out.toByteArray());
|
||||||
Template tmpl = new OptionalTemplate(DynamicTemplate
|
Template tmpl = new NullableTemplate(DynamicTemplate
|
||||||
.create(GeneralReferenceTypeFieldsClass.class));
|
.create(GeneralReferenceTypeFieldsClass.class));
|
||||||
Unpacker pac = new Unpacker(in);
|
Unpacker pac = new Unpacker(in);
|
||||||
Iterator<MessagePackObject> it = pac.iterator();
|
Iterator<MessagePackObject> it = pac.iterator();
|
||||||
@ -371,7 +371,7 @@ public class TestPackConvert extends TestCase {
|
|||||||
.create(OptionalGeneralReferenceTypeFieldsClass.class));
|
.create(OptionalGeneralReferenceTypeFieldsClass.class));
|
||||||
packer.pack(new Packer(out), src);
|
packer.pack(new Packer(out), src);
|
||||||
ByteArrayInputStream in = new ByteArrayInputStream(out.toByteArray());
|
ByteArrayInputStream in = new ByteArrayInputStream(out.toByteArray());
|
||||||
Template tmpl = new OptionalTemplate(DynamicTemplate
|
Template tmpl = new NullableTemplate(DynamicTemplate
|
||||||
.create(OptionalGeneralReferenceTypeFieldsClass.class));
|
.create(OptionalGeneralReferenceTypeFieldsClass.class));
|
||||||
Unpacker pac = new Unpacker(in);
|
Unpacker pac = new Unpacker(in);
|
||||||
Iterator<MessagePackObject> it = pac.iterator();
|
Iterator<MessagePackObject> it = pac.iterator();
|
||||||
@ -487,7 +487,7 @@ public class TestPackConvert extends TestCase {
|
|||||||
.create(SampleListTypes.class));
|
.create(SampleListTypes.class));
|
||||||
packer.pack(new Packer(out), src);
|
packer.pack(new Packer(out), src);
|
||||||
ByteArrayInputStream in = new ByteArrayInputStream(out.toByteArray());
|
ByteArrayInputStream in = new ByteArrayInputStream(out.toByteArray());
|
||||||
Template tmpl = new OptionalTemplate(DynamicTemplate
|
Template tmpl = new NullableTemplate(DynamicTemplate
|
||||||
.create(SampleListTypes.class));
|
.create(SampleListTypes.class));
|
||||||
Unpacker pac = new Unpacker(in);
|
Unpacker pac = new Unpacker(in);
|
||||||
Iterator<MessagePackObject> it = pac.iterator();
|
Iterator<MessagePackObject> it = pac.iterator();
|
||||||
@ -627,7 +627,7 @@ public class TestPackConvert extends TestCase {
|
|||||||
.create(SampleOptionalListTypes.class));
|
.create(SampleOptionalListTypes.class));
|
||||||
packer.pack(new Packer(out), src);
|
packer.pack(new Packer(out), src);
|
||||||
ByteArrayInputStream in = new ByteArrayInputStream(out.toByteArray());
|
ByteArrayInputStream in = new ByteArrayInputStream(out.toByteArray());
|
||||||
Template tmpl = new OptionalTemplate(DynamicTemplate
|
Template tmpl = new NullableTemplate(DynamicTemplate
|
||||||
.create(SampleOptionalListTypes.class));
|
.create(SampleOptionalListTypes.class));
|
||||||
Unpacker pac = new Unpacker(in);
|
Unpacker pac = new Unpacker(in);
|
||||||
Iterator<MessagePackObject> it = pac.iterator();
|
Iterator<MessagePackObject> it = pac.iterator();
|
||||||
@ -720,7 +720,7 @@ public class TestPackConvert extends TestCase {
|
|||||||
.create(SampleMapTypes.class));
|
.create(SampleMapTypes.class));
|
||||||
packer.pack(new Packer(out), src);
|
packer.pack(new Packer(out), src);
|
||||||
ByteArrayInputStream in = new ByteArrayInputStream(out.toByteArray());
|
ByteArrayInputStream in = new ByteArrayInputStream(out.toByteArray());
|
||||||
Template tmpl = new OptionalTemplate(DynamicTemplate
|
Template tmpl = new NullableTemplate(DynamicTemplate
|
||||||
.create(SampleMapTypes.class));
|
.create(SampleMapTypes.class));
|
||||||
Unpacker pac = new Unpacker(in);
|
Unpacker pac = new Unpacker(in);
|
||||||
Iterator<MessagePackObject> it = pac.iterator();
|
Iterator<MessagePackObject> it = pac.iterator();
|
||||||
@ -816,7 +816,7 @@ public class TestPackConvert extends TestCase {
|
|||||||
.create(SampleOptionalMapTypes.class));
|
.create(SampleOptionalMapTypes.class));
|
||||||
packer.pack(new Packer(out), src);
|
packer.pack(new Packer(out), src);
|
||||||
ByteArrayInputStream in = new ByteArrayInputStream(out.toByteArray());
|
ByteArrayInputStream in = new ByteArrayInputStream(out.toByteArray());
|
||||||
Template tmpl = new OptionalTemplate(DynamicTemplate
|
Template tmpl = new NullableTemplate(DynamicTemplate
|
||||||
.create(SampleOptionalMapTypes.class));
|
.create(SampleOptionalMapTypes.class));
|
||||||
Unpacker pac = new Unpacker(in);
|
Unpacker pac = new Unpacker(in);
|
||||||
Iterator<MessagePackObject> it = pac.iterator();
|
Iterator<MessagePackObject> it = pac.iterator();
|
||||||
@ -1086,7 +1086,7 @@ public class TestPackConvert extends TestCase {
|
|||||||
.create(SampleEnumFieldClass.class));
|
.create(SampleEnumFieldClass.class));
|
||||||
packer.pack(new Packer(out), src);
|
packer.pack(new Packer(out), src);
|
||||||
ByteArrayInputStream in = new ByteArrayInputStream(out.toByteArray());
|
ByteArrayInputStream in = new ByteArrayInputStream(out.toByteArray());
|
||||||
Template tmpl = new OptionalTemplate(DynamicTemplate
|
Template tmpl = new NullableTemplate(DynamicTemplate
|
||||||
.create(SampleEnumFieldClass.class));
|
.create(SampleEnumFieldClass.class));
|
||||||
Unpacker pac = new Unpacker(in);
|
Unpacker pac = new Unpacker(in);
|
||||||
Iterator<MessagePackObject> it = pac.iterator();
|
Iterator<MessagePackObject> it = pac.iterator();
|
||||||
@ -1163,7 +1163,7 @@ public class TestPackConvert extends TestCase {
|
|||||||
.create(SampleOptionalEnumFieldClass.class));
|
.create(SampleOptionalEnumFieldClass.class));
|
||||||
packer.pack(new Packer(out), src);
|
packer.pack(new Packer(out), src);
|
||||||
ByteArrayInputStream in = new ByteArrayInputStream(out.toByteArray());
|
ByteArrayInputStream in = new ByteArrayInputStream(out.toByteArray());
|
||||||
Template tmpl = new OptionalTemplate(DynamicTemplate
|
Template tmpl = new NullableTemplate(DynamicTemplate
|
||||||
.create(SampleOptionalEnumFieldClass.class));
|
.create(SampleOptionalEnumFieldClass.class));
|
||||||
Unpacker pac = new Unpacker(in);
|
Unpacker pac = new Unpacker(in);
|
||||||
Iterator<MessagePackObject> it = pac.iterator();
|
Iterator<MessagePackObject> it = pac.iterator();
|
||||||
@ -1279,13 +1279,13 @@ public class TestPackConvert extends TestCase {
|
|||||||
src2.f2 = 2;
|
src2.f2 = 2;
|
||||||
src.f1 = src2;
|
src.f1 = src2;
|
||||||
ByteArrayOutputStream out = new ByteArrayOutputStream();
|
ByteArrayOutputStream out = new ByteArrayOutputStream();
|
||||||
tmpl.pack(new Packer(out), src);
|
new Packer(out).pack(src);
|
||||||
ByteArrayInputStream in = new ByteArrayInputStream(out.toByteArray());
|
ByteArrayInputStream in = new ByteArrayInputStream(out.toByteArray());
|
||||||
Unpacker pac = new Unpacker(in);
|
Unpacker pac = new Unpacker(in);
|
||||||
Iterator<MessagePackObject> it = pac.iterator();
|
Iterator<MessagePackObject> it = pac.iterator();
|
||||||
assertTrue(it.hasNext());
|
assertTrue(it.hasNext());
|
||||||
MessagePackObject mpo = it.next();
|
MessagePackObject mpo = it.next();
|
||||||
BaseClass dst = (BaseClass) tmpl.convert(mpo);
|
BaseClass dst = mpo.convert(BaseClass.class);
|
||||||
assertTrue(src.f0 == dst.f0);
|
assertTrue(src.f0 == dst.f0);
|
||||||
assertTrue(src.f1.f2 == dst.f1.f2);
|
assertTrue(src.f1.f2 == dst.f1.f2);
|
||||||
assertFalse(it.hasNext());
|
assertFalse(it.hasNext());
|
||||||
@ -1295,17 +1295,17 @@ public class TestPackConvert extends TestCase {
|
|||||||
public void testNestedFieldClass02() throws Exception {
|
public void testNestedFieldClass02() throws Exception {
|
||||||
Template tmpl2 = DynamicTemplate.create(NestedClass.class);
|
Template tmpl2 = DynamicTemplate.create(NestedClass.class);
|
||||||
CustomMessage.register(NestedClass.class, tmpl2);
|
CustomMessage.register(NestedClass.class, tmpl2);
|
||||||
Template tmpl = new OptionalTemplate(DynamicTemplate.create(BaseClass.class));
|
Template tmpl = DynamicTemplate.create(BaseClass.class);
|
||||||
CustomMessage.register(BaseClass.class, tmpl);
|
CustomMessage.register(BaseClass.class, tmpl);
|
||||||
BaseClass src = null;
|
BaseClass src = null;
|
||||||
ByteArrayOutputStream out = new ByteArrayOutputStream();
|
ByteArrayOutputStream out = new ByteArrayOutputStream();
|
||||||
tmpl.pack(new Packer(out), src);
|
new Packer(out).pack(src);
|
||||||
ByteArrayInputStream in = new ByteArrayInputStream(out.toByteArray());
|
ByteArrayInputStream in = new ByteArrayInputStream(out.toByteArray());
|
||||||
Unpacker pac = new Unpacker(in);
|
Unpacker pac = new Unpacker(in);
|
||||||
Iterator<MessagePackObject> it = pac.iterator();
|
Iterator<MessagePackObject> it = pac.iterator();
|
||||||
assertTrue(it.hasNext());
|
assertTrue(it.hasNext());
|
||||||
MessagePackObject mpo = it.next();
|
MessagePackObject mpo = it.next();
|
||||||
BaseClass dst = (BaseClass) tmpl.convert(mpo);
|
BaseClass dst = mpo.convert(BaseClass.class);
|
||||||
assertEquals(src, dst);
|
assertEquals(src, dst);
|
||||||
assertFalse(it.hasNext());
|
assertFalse(it.hasNext());
|
||||||
}
|
}
|
||||||
@ -1337,13 +1337,13 @@ public class TestPackConvert extends TestCase {
|
|||||||
src2.f2 = 2;
|
src2.f2 = 2;
|
||||||
src.f1 = src2;
|
src.f1 = src2;
|
||||||
ByteArrayOutputStream out = new ByteArrayOutputStream();
|
ByteArrayOutputStream out = new ByteArrayOutputStream();
|
||||||
tmpl.pack(new Packer(out), src);
|
new Packer(out).pack(src);
|
||||||
ByteArrayInputStream in = new ByteArrayInputStream(out.toByteArray());
|
ByteArrayInputStream in = new ByteArrayInputStream(out.toByteArray());
|
||||||
Unpacker pac = new Unpacker(in);
|
Unpacker pac = new Unpacker(in);
|
||||||
Iterator<MessagePackObject> it = pac.iterator();
|
Iterator<MessagePackObject> it = pac.iterator();
|
||||||
assertTrue(it.hasNext());
|
assertTrue(it.hasNext());
|
||||||
MessagePackObject mpo = it.next();
|
MessagePackObject mpo = it.next();
|
||||||
OptionalBaseClass dst = (OptionalBaseClass) tmpl.convert(mpo);
|
OptionalBaseClass dst = mpo.convert(OptionalBaseClass.class);
|
||||||
assertTrue(src.f0 == dst.f0);
|
assertTrue(src.f0 == dst.f0);
|
||||||
assertTrue(src.f1.f2 == dst.f1.f2);
|
assertTrue(src.f1.f2 == dst.f1.f2);
|
||||||
assertFalse(it.hasNext());
|
assertFalse(it.hasNext());
|
||||||
@ -1357,13 +1357,13 @@ public class TestPackConvert extends TestCase {
|
|||||||
CustomMessage.register(OptionalBaseClass.class, tmpl);
|
CustomMessage.register(OptionalBaseClass.class, tmpl);
|
||||||
OptionalBaseClass src = new OptionalBaseClass();
|
OptionalBaseClass src = new OptionalBaseClass();
|
||||||
ByteArrayOutputStream out = new ByteArrayOutputStream();
|
ByteArrayOutputStream out = new ByteArrayOutputStream();
|
||||||
tmpl.pack(new Packer(out), src);
|
new Packer(out).pack(src);
|
||||||
ByteArrayInputStream in = new ByteArrayInputStream(out.toByteArray());
|
ByteArrayInputStream in = new ByteArrayInputStream(out.toByteArray());
|
||||||
Unpacker pac = new Unpacker(in);
|
Unpacker pac = new Unpacker(in);
|
||||||
Iterator<MessagePackObject> it = pac.iterator();
|
Iterator<MessagePackObject> it = pac.iterator();
|
||||||
assertTrue(it.hasNext());
|
assertTrue(it.hasNext());
|
||||||
MessagePackObject mpo = it.next();
|
MessagePackObject mpo = it.next();
|
||||||
OptionalBaseClass dst = (OptionalBaseClass) tmpl.convert(mpo);
|
OptionalBaseClass dst = mpo.convert(OptionalBaseClass.class);
|
||||||
assertTrue(src.f0 == dst.f0);
|
assertTrue(src.f0 == dst.f0);
|
||||||
assertEquals(src.f1, dst.f1);
|
assertEquals(src.f1, dst.f1);
|
||||||
assertFalse(it.hasNext());
|
assertFalse(it.hasNext());
|
||||||
@ -1379,8 +1379,7 @@ public class TestPackConvert extends TestCase {
|
|||||||
Template tmpl2 = DynamicTemplate.create(NestedClass.class);
|
Template tmpl2 = DynamicTemplate.create(NestedClass.class);
|
||||||
CustomUnpacker.register(NestedClass.class, tmpl2);
|
CustomUnpacker.register(NestedClass.class, tmpl2);
|
||||||
CustomConverter.register(NestedClass.class, tmpl2);
|
CustomConverter.register(NestedClass.class, tmpl2);
|
||||||
Template tmpl = new OptionalTemplate(DynamicTemplate
|
Template tmpl = DynamicTemplate.create(BaseClass.class);
|
||||||
.create(BaseClass.class));
|
|
||||||
CustomUnpacker.register(BaseClass.class, tmpl);
|
CustomUnpacker.register(BaseClass.class, tmpl);
|
||||||
CustomConverter.register(BaseClass.class, tmpl);
|
CustomConverter.register(BaseClass.class, tmpl);
|
||||||
BaseClass src = null;
|
BaseClass src = null;
|
||||||
@ -1391,7 +1390,7 @@ public class TestPackConvert extends TestCase {
|
|||||||
Iterator<MessagePackObject> it = pac.iterator();
|
Iterator<MessagePackObject> it = pac.iterator();
|
||||||
assertTrue(it.hasNext());
|
assertTrue(it.hasNext());
|
||||||
MessagePackObject mpo = it.next();
|
MessagePackObject mpo = it.next();
|
||||||
BaseClass dst = (BaseClass) tmpl.convert(mpo);
|
BaseClass dst = mpo.convert(BaseClass.class);
|
||||||
assertEquals(src, dst);
|
assertEquals(src, dst);
|
||||||
assertFalse(it.hasNext());
|
assertFalse(it.hasNext());
|
||||||
}
|
}
|
||||||
@ -1448,7 +1447,7 @@ public class TestPackConvert extends TestCase {
|
|||||||
Iterator<MessagePackObject> it = pac.iterator();
|
Iterator<MessagePackObject> it = pac.iterator();
|
||||||
assertTrue(it.hasNext());
|
assertTrue(it.hasNext());
|
||||||
MessagePackObject mpo = it.next();
|
MessagePackObject mpo = it.next();
|
||||||
Template tmpl = new OptionalTemplate(DynamicTemplate
|
Template tmpl = new NullableTemplate(DynamicTemplate
|
||||||
.create(BaseClass2.class));
|
.create(BaseClass2.class));
|
||||||
BaseClass2 dst = (BaseClass2) tmpl.convert(mpo);
|
BaseClass2 dst = (BaseClass2) tmpl.convert(mpo);
|
||||||
assertEquals(src, dst);
|
assertEquals(src, dst);
|
||||||
@ -1523,7 +1522,7 @@ public class TestPackConvert extends TestCase {
|
|||||||
Iterator<MessagePackObject> it = pac.iterator();
|
Iterator<MessagePackObject> it = pac.iterator();
|
||||||
assertTrue(it.hasNext());
|
assertTrue(it.hasNext());
|
||||||
MessagePackObject mpo = it.next();
|
MessagePackObject mpo = it.next();
|
||||||
Template tmpl = new OptionalTemplate(DynamicTemplate
|
Template tmpl = new NullableTemplate(DynamicTemplate
|
||||||
.create(OptionalBaseClass2.class));
|
.create(OptionalBaseClass2.class));
|
||||||
OptionalBaseClass2 dst = (OptionalBaseClass2) tmpl.convert(mpo);
|
OptionalBaseClass2 dst = (OptionalBaseClass2) tmpl.convert(mpo);
|
||||||
assertEquals(src, dst);
|
assertEquals(src, dst);
|
||||||
@ -1589,7 +1588,7 @@ public class TestPackConvert extends TestCase {
|
|||||||
.create(SampleSubClass.class));
|
.create(SampleSubClass.class));
|
||||||
packer.pack(new Packer(out), src);
|
packer.pack(new Packer(out), src);
|
||||||
ByteArrayInputStream in = new ByteArrayInputStream(out.toByteArray());
|
ByteArrayInputStream in = new ByteArrayInputStream(out.toByteArray());
|
||||||
Template tmpl = new OptionalTemplate(DynamicTemplate
|
Template tmpl = new NullableTemplate(DynamicTemplate
|
||||||
.create(SampleSubClass.class));
|
.create(SampleSubClass.class));
|
||||||
Unpacker pac = new Unpacker(in);
|
Unpacker pac = new Unpacker(in);
|
||||||
Iterator<MessagePackObject> it = pac.iterator();
|
Iterator<MessagePackObject> it = pac.iterator();
|
||||||
@ -1664,7 +1663,7 @@ public class TestPackConvert extends TestCase {
|
|||||||
.create(SampleOptionalSubClass.class));
|
.create(SampleOptionalSubClass.class));
|
||||||
packer.pack(new Packer(out), src);
|
packer.pack(new Packer(out), src);
|
||||||
ByteArrayInputStream in = new ByteArrayInputStream(out.toByteArray());
|
ByteArrayInputStream in = new ByteArrayInputStream(out.toByteArray());
|
||||||
Template tmpl = new OptionalTemplate(DynamicTemplate
|
Template tmpl = new NullableTemplate(DynamicTemplate
|
||||||
.create(SampleOptionalSubClass.class));
|
.create(SampleOptionalSubClass.class));
|
||||||
Unpacker pac = new Unpacker(in);
|
Unpacker pac = new Unpacker(in);
|
||||||
Iterator<MessagePackObject> it = pac.iterator();
|
Iterator<MessagePackObject> it = pac.iterator();
|
||||||
@ -1741,7 +1740,7 @@ public class TestPackConvert extends TestCase {
|
|||||||
.create(BaseMessagePackableConvertableClass.class));
|
.create(BaseMessagePackableConvertableClass.class));
|
||||||
packer.pack(new Packer(out), src);
|
packer.pack(new Packer(out), src);
|
||||||
ByteArrayInputStream in = new ByteArrayInputStream(out.toByteArray());
|
ByteArrayInputStream in = new ByteArrayInputStream(out.toByteArray());
|
||||||
Template tmpl = new OptionalTemplate(DynamicTemplate
|
Template tmpl = new NullableTemplate(DynamicTemplate
|
||||||
.create(BaseMessagePackableConvertableClass.class));
|
.create(BaseMessagePackableConvertableClass.class));
|
||||||
Unpacker pac = new Unpacker(in);
|
Unpacker pac = new Unpacker(in);
|
||||||
Iterator<MessagePackObject> it = pac.iterator();
|
Iterator<MessagePackObject> it = pac.iterator();
|
||||||
@ -1855,7 +1854,7 @@ public class TestPackConvert extends TestCase {
|
|||||||
.create(OptionalBaseMessagePackableConvertableClass.class));
|
.create(OptionalBaseMessagePackableConvertableClass.class));
|
||||||
packer.pack(new Packer(out), src);
|
packer.pack(new Packer(out), src);
|
||||||
ByteArrayInputStream in = new ByteArrayInputStream(out.toByteArray());
|
ByteArrayInputStream in = new ByteArrayInputStream(out.toByteArray());
|
||||||
Template tmpl = new OptionalTemplate(DynamicTemplate
|
Template tmpl = new NullableTemplate(DynamicTemplate
|
||||||
.create(OptionalBaseMessagePackableConvertableClass.class));
|
.create(OptionalBaseMessagePackableConvertableClass.class));
|
||||||
Unpacker pac = new Unpacker(in);
|
Unpacker pac = new Unpacker(in);
|
||||||
Iterator<MessagePackObject> it = pac.iterator();
|
Iterator<MessagePackObject> it = pac.iterator();
|
||||||
|
@ -20,6 +20,7 @@ import org.msgpack.packer.OptionalPacker;
|
|||||||
import org.msgpack.template.ListTemplate;
|
import org.msgpack.template.ListTemplate;
|
||||||
import org.msgpack.template.MapTemplate;
|
import org.msgpack.template.MapTemplate;
|
||||||
import org.msgpack.template.OptionalTemplate;
|
import org.msgpack.template.OptionalTemplate;
|
||||||
|
import org.msgpack.template.NullableTemplate;
|
||||||
import static org.msgpack.Templates.tBigInteger;
|
import static org.msgpack.Templates.tBigInteger;
|
||||||
import static org.msgpack.Templates.tBoolean;
|
import static org.msgpack.Templates.tBoolean;
|
||||||
import static org.msgpack.Templates.tByte;
|
import static org.msgpack.Templates.tByte;
|
||||||
@ -125,7 +126,7 @@ public class TestPackConvertWithFieldOption extends TestCase {
|
|||||||
PrimitiveTypeFieldsClass.class, opts));
|
PrimitiveTypeFieldsClass.class, opts));
|
||||||
packer.pack(new Packer(out), src);
|
packer.pack(new Packer(out), src);
|
||||||
ByteArrayInputStream in = new ByteArrayInputStream(out.toByteArray());
|
ByteArrayInputStream in = new ByteArrayInputStream(out.toByteArray());
|
||||||
Template tmpl = new OptionalTemplate(DynamicTemplate.create(PrimitiveTypeFieldsClass.class, opts));
|
Template tmpl = new NullableTemplate(DynamicTemplate.create(PrimitiveTypeFieldsClass.class, opts));
|
||||||
Unpacker pac = new Unpacker(in);
|
Unpacker pac = new Unpacker(in);
|
||||||
Iterator<MessagePackObject> it = pac.iterator();
|
Iterator<MessagePackObject> it = pac.iterator();
|
||||||
assertTrue(it.hasNext());
|
assertTrue(it.hasNext());
|
||||||
@ -268,7 +269,7 @@ public class TestPackConvertWithFieldOption extends TestCase {
|
|||||||
.create(GeneralReferenceTypeFieldsClass.class, opts));
|
.create(GeneralReferenceTypeFieldsClass.class, opts));
|
||||||
packer.pack(new Packer(out), src);
|
packer.pack(new Packer(out), src);
|
||||||
ByteArrayInputStream in = new ByteArrayInputStream(out.toByteArray());
|
ByteArrayInputStream in = new ByteArrayInputStream(out.toByteArray());
|
||||||
Template tmpl = new OptionalTemplate(DynamicTemplate
|
Template tmpl = new NullableTemplate(DynamicTemplate
|
||||||
.create(GeneralReferenceTypeFieldsClass.class, opts));
|
.create(GeneralReferenceTypeFieldsClass.class, opts));
|
||||||
Unpacker pac = new Unpacker(in);
|
Unpacker pac = new Unpacker(in);
|
||||||
Iterator<MessagePackObject> it = pac.iterator();
|
Iterator<MessagePackObject> it = pac.iterator();
|
||||||
@ -410,7 +411,7 @@ public class TestPackConvertWithFieldOption extends TestCase {
|
|||||||
.create(SampleListTypes.class));
|
.create(SampleListTypes.class));
|
||||||
packer.pack(new Packer(out), src);
|
packer.pack(new Packer(out), src);
|
||||||
ByteArrayInputStream in = new ByteArrayInputStream(out.toByteArray());
|
ByteArrayInputStream in = new ByteArrayInputStream(out.toByteArray());
|
||||||
Template tmpl = new OptionalTemplate(DynamicTemplate
|
Template tmpl = new NullableTemplate(DynamicTemplate
|
||||||
.create(SampleListTypes.class, opts));
|
.create(SampleListTypes.class, opts));
|
||||||
Unpacker pac = new Unpacker(in);
|
Unpacker pac = new Unpacker(in);
|
||||||
Iterator<MessagePackObject> it = pac.iterator();
|
Iterator<MessagePackObject> it = pac.iterator();
|
||||||
@ -532,7 +533,7 @@ public class TestPackConvertWithFieldOption extends TestCase {
|
|||||||
.create(SampleMapTypes.class, opts));
|
.create(SampleMapTypes.class, opts));
|
||||||
packer.pack(new Packer(out), src);
|
packer.pack(new Packer(out), src);
|
||||||
ByteArrayInputStream in = new ByteArrayInputStream(out.toByteArray());
|
ByteArrayInputStream in = new ByteArrayInputStream(out.toByteArray());
|
||||||
Template tmpl = new OptionalTemplate(DynamicTemplate.create(SampleMapTypes.class, opts));
|
Template tmpl = new NullableTemplate(DynamicTemplate.create(SampleMapTypes.class, opts));
|
||||||
Unpacker pac = new Unpacker(in);
|
Unpacker pac = new Unpacker(in);
|
||||||
Iterator<MessagePackObject> it = pac.iterator();
|
Iterator<MessagePackObject> it = pac.iterator();
|
||||||
assertTrue(it.hasNext());
|
assertTrue(it.hasNext());
|
||||||
|
@ -24,7 +24,7 @@ import org.msgpack.annotation.MessagePackMessage;
|
|||||||
import org.msgpack.annotation.MessagePackOptional;
|
import org.msgpack.annotation.MessagePackOptional;
|
||||||
import org.msgpack.annotation.MessagePackOrdinalEnum;
|
import org.msgpack.annotation.MessagePackOrdinalEnum;
|
||||||
import org.msgpack.packer.OptionalPacker;
|
import org.msgpack.packer.OptionalPacker;
|
||||||
import org.msgpack.template.OptionalTemplate;
|
import org.msgpack.template.NullableTemplate;
|
||||||
|
|
||||||
import junit.framework.TestCase;
|
import junit.framework.TestCase;
|
||||||
|
|
||||||
@ -85,7 +85,7 @@ public class TestPackUnpack extends TestCase {
|
|||||||
.create(PrimitiveTypeFieldsClass.class));
|
.create(PrimitiveTypeFieldsClass.class));
|
||||||
packer.pack(new Packer(out), src);
|
packer.pack(new Packer(out), src);
|
||||||
ByteArrayInputStream in = new ByteArrayInputStream(out.toByteArray());
|
ByteArrayInputStream in = new ByteArrayInputStream(out.toByteArray());
|
||||||
Template tmpl = new OptionalTemplate(DynamicTemplate
|
Template tmpl = new NullableTemplate(DynamicTemplate
|
||||||
.create(PrimitiveTypeFieldsClass.class));
|
.create(PrimitiveTypeFieldsClass.class));
|
||||||
PrimitiveTypeFieldsClass dst = (PrimitiveTypeFieldsClass) tmpl
|
PrimitiveTypeFieldsClass dst = (PrimitiveTypeFieldsClass) tmpl
|
||||||
.unpack(new Unpacker(in));
|
.unpack(new Unpacker(in));
|
||||||
@ -162,7 +162,7 @@ public class TestPackUnpack extends TestCase {
|
|||||||
.create(OptionalPrimitiveTypeFieldsClass.class));
|
.create(OptionalPrimitiveTypeFieldsClass.class));
|
||||||
packer.pack(new Packer(out), src);
|
packer.pack(new Packer(out), src);
|
||||||
ByteArrayInputStream in = new ByteArrayInputStream(out.toByteArray());
|
ByteArrayInputStream in = new ByteArrayInputStream(out.toByteArray());
|
||||||
Template tmpl = new OptionalTemplate(DynamicTemplate
|
Template tmpl = new NullableTemplate(DynamicTemplate
|
||||||
.create(OptionalPrimitiveTypeFieldsClass.class));
|
.create(OptionalPrimitiveTypeFieldsClass.class));
|
||||||
OptionalPrimitiveTypeFieldsClass dst = (OptionalPrimitiveTypeFieldsClass) tmpl
|
OptionalPrimitiveTypeFieldsClass dst = (OptionalPrimitiveTypeFieldsClass) tmpl
|
||||||
.unpack(new Unpacker(in));
|
.unpack(new Unpacker(in));
|
||||||
@ -234,7 +234,7 @@ public class TestPackUnpack extends TestCase {
|
|||||||
.create(GeneralReferenceTypeFieldsClass.class));
|
.create(GeneralReferenceTypeFieldsClass.class));
|
||||||
packer.pack(new Packer(out), src);
|
packer.pack(new Packer(out), src);
|
||||||
ByteArrayInputStream in = new ByteArrayInputStream(out.toByteArray());
|
ByteArrayInputStream in = new ByteArrayInputStream(out.toByteArray());
|
||||||
Template tmpl = new OptionalTemplate(DynamicTemplate
|
Template tmpl = new NullableTemplate(DynamicTemplate
|
||||||
.create(GeneralReferenceTypeFieldsClass.class));
|
.create(GeneralReferenceTypeFieldsClass.class));
|
||||||
GeneralReferenceTypeFieldsClass dst = (GeneralReferenceTypeFieldsClass) tmpl
|
GeneralReferenceTypeFieldsClass dst = (GeneralReferenceTypeFieldsClass) tmpl
|
||||||
.unpack(new Unpacker(in));
|
.unpack(new Unpacker(in));
|
||||||
@ -342,7 +342,7 @@ public class TestPackUnpack extends TestCase {
|
|||||||
.create(GeneralOptionalReferenceTypeFieldsClass.class));
|
.create(GeneralOptionalReferenceTypeFieldsClass.class));
|
||||||
packer.pack(new Packer(out), src);
|
packer.pack(new Packer(out), src);
|
||||||
ByteArrayInputStream in = new ByteArrayInputStream(out.toByteArray());
|
ByteArrayInputStream in = new ByteArrayInputStream(out.toByteArray());
|
||||||
Template tmpl = new OptionalTemplate(DynamicTemplate
|
Template tmpl = new NullableTemplate(DynamicTemplate
|
||||||
.create(GeneralOptionalReferenceTypeFieldsClass.class));
|
.create(GeneralOptionalReferenceTypeFieldsClass.class));
|
||||||
GeneralOptionalReferenceTypeFieldsClass dst = (GeneralOptionalReferenceTypeFieldsClass) tmpl
|
GeneralOptionalReferenceTypeFieldsClass dst = (GeneralOptionalReferenceTypeFieldsClass) tmpl
|
||||||
.unpack(new Unpacker(in));
|
.unpack(new Unpacker(in));
|
||||||
@ -448,7 +448,7 @@ public class TestPackUnpack extends TestCase {
|
|||||||
.create(SampleListTypes.class));
|
.create(SampleListTypes.class));
|
||||||
packer.pack(new Packer(out), src);
|
packer.pack(new Packer(out), src);
|
||||||
ByteArrayInputStream in = new ByteArrayInputStream(out.toByteArray());
|
ByteArrayInputStream in = new ByteArrayInputStream(out.toByteArray());
|
||||||
Template tmpl = new OptionalTemplate(DynamicTemplate
|
Template tmpl = new NullableTemplate(DynamicTemplate
|
||||||
.create(SampleListTypes.class));
|
.create(SampleListTypes.class));
|
||||||
SampleListTypes dst = (SampleListTypes) tmpl.unpack(new Unpacker(in));
|
SampleListTypes dst = (SampleListTypes) tmpl.unpack(new Unpacker(in));
|
||||||
assertEquals(src, dst);
|
assertEquals(src, dst);
|
||||||
@ -573,7 +573,7 @@ public class TestPackUnpack extends TestCase {
|
|||||||
.create(SampleOptionalListTypes.class));
|
.create(SampleOptionalListTypes.class));
|
||||||
packer.pack(new Packer(out), src);
|
packer.pack(new Packer(out), src);
|
||||||
ByteArrayInputStream in = new ByteArrayInputStream(out.toByteArray());
|
ByteArrayInputStream in = new ByteArrayInputStream(out.toByteArray());
|
||||||
Template tmpl = new OptionalTemplate(DynamicTemplate
|
Template tmpl = new NullableTemplate(DynamicTemplate
|
||||||
.create(SampleOptionalListTypes.class));
|
.create(SampleOptionalListTypes.class));
|
||||||
SampleListTypes dst = (SampleListTypes) tmpl.unpack(new Unpacker(in));
|
SampleListTypes dst = (SampleListTypes) tmpl.unpack(new Unpacker(in));
|
||||||
assertEquals(src, dst);
|
assertEquals(src, dst);
|
||||||
@ -655,7 +655,7 @@ public class TestPackUnpack extends TestCase {
|
|||||||
.create(SampleMapTypes.class));
|
.create(SampleMapTypes.class));
|
||||||
packer.pack(new Packer(out), src);
|
packer.pack(new Packer(out), src);
|
||||||
ByteArrayInputStream in = new ByteArrayInputStream(out.toByteArray());
|
ByteArrayInputStream in = new ByteArrayInputStream(out.toByteArray());
|
||||||
Template tmpl = new OptionalTemplate(DynamicTemplate
|
Template tmpl = new NullableTemplate(DynamicTemplate
|
||||||
.create(SampleMapTypes.class));
|
.create(SampleMapTypes.class));
|
||||||
SampleMapTypes dst = (SampleMapTypes) tmpl.unpack(new Unpacker(in));
|
SampleMapTypes dst = (SampleMapTypes) tmpl.unpack(new Unpacker(in));
|
||||||
assertEquals(src, dst);
|
assertEquals(src, dst);
|
||||||
@ -738,7 +738,7 @@ public class TestPackUnpack extends TestCase {
|
|||||||
.create(SampleOptionalMapTypes.class));
|
.create(SampleOptionalMapTypes.class));
|
||||||
packer.pack(new Packer(out), src);
|
packer.pack(new Packer(out), src);
|
||||||
ByteArrayInputStream in = new ByteArrayInputStream(out.toByteArray());
|
ByteArrayInputStream in = new ByteArrayInputStream(out.toByteArray());
|
||||||
Template tmpl = new OptionalTemplate(DynamicTemplate
|
Template tmpl = new NullableTemplate(DynamicTemplate
|
||||||
.create(SampleOptionalMapTypes.class));
|
.create(SampleOptionalMapTypes.class));
|
||||||
SampleOptionalMapTypes dst = (SampleOptionalMapTypes) tmpl
|
SampleOptionalMapTypes dst = (SampleOptionalMapTypes) tmpl
|
||||||
.unpack(new Unpacker(in));
|
.unpack(new Unpacker(in));
|
||||||
@ -993,7 +993,7 @@ public class TestPackUnpack extends TestCase {
|
|||||||
.create(SampleEnumFieldClass.class));
|
.create(SampleEnumFieldClass.class));
|
||||||
packer.pack(new Packer(out), src);
|
packer.pack(new Packer(out), src);
|
||||||
ByteArrayInputStream in = new ByteArrayInputStream(out.toByteArray());
|
ByteArrayInputStream in = new ByteArrayInputStream(out.toByteArray());
|
||||||
Template tmpl = new OptionalTemplate(DynamicTemplate
|
Template tmpl = new NullableTemplate(DynamicTemplate
|
||||||
.create(SampleEnumFieldClass.class));
|
.create(SampleEnumFieldClass.class));
|
||||||
SampleEnumFieldClass dst = (SampleEnumFieldClass) tmpl
|
SampleEnumFieldClass dst = (SampleEnumFieldClass) tmpl
|
||||||
.unpack(new Unpacker(in));
|
.unpack(new Unpacker(in));
|
||||||
@ -1057,7 +1057,7 @@ public class TestPackUnpack extends TestCase {
|
|||||||
.create(SampleEnumFieldClass.class));
|
.create(SampleEnumFieldClass.class));
|
||||||
packer.pack(new Packer(out), src);
|
packer.pack(new Packer(out), src);
|
||||||
ByteArrayInputStream in = new ByteArrayInputStream(out.toByteArray());
|
ByteArrayInputStream in = new ByteArrayInputStream(out.toByteArray());
|
||||||
Template tmpl = new OptionalTemplate(DynamicTemplate
|
Template tmpl = new NullableTemplate(DynamicTemplate
|
||||||
.create(SampleEnumFieldClass.class));
|
.create(SampleEnumFieldClass.class));
|
||||||
SampleEnumFieldClass dst = (SampleEnumFieldClass) tmpl
|
SampleEnumFieldClass dst = (SampleEnumFieldClass) tmpl
|
||||||
.unpack(new Unpacker(in));
|
.unpack(new Unpacker(in));
|
||||||
@ -1171,7 +1171,7 @@ public class TestPackUnpack extends TestCase {
|
|||||||
public void testNestedFieldClass01() throws Exception {
|
public void testNestedFieldClass01() throws Exception {
|
||||||
Template tmpl2 = DynamicTemplate.create(NestedClass.class);
|
Template tmpl2 = DynamicTemplate.create(NestedClass.class);
|
||||||
CustomMessage.register(NestedClass.class, tmpl2);
|
CustomMessage.register(NestedClass.class, tmpl2);
|
||||||
Template tmpl = new OptionalTemplate(DynamicTemplate.create(BaseClass.class));
|
Template tmpl = new NullableTemplate(DynamicTemplate.create(BaseClass.class));
|
||||||
BaseClass src = null;
|
BaseClass src = null;
|
||||||
ByteArrayOutputStream out = new ByteArrayOutputStream();
|
ByteArrayOutputStream out = new ByteArrayOutputStream();
|
||||||
tmpl.pack(new Packer(out), src);
|
tmpl.pack(new Packer(out), src);
|
||||||
@ -1233,7 +1233,7 @@ public class TestPackUnpack extends TestCase {
|
|||||||
public void testOptionalNestedFieldClass02() throws Exception {
|
public void testOptionalNestedFieldClass02() throws Exception {
|
||||||
Template tmpl2 = DynamicTemplate.create(OptionalNestedClass.class);
|
Template tmpl2 = DynamicTemplate.create(OptionalNestedClass.class);
|
||||||
CustomMessage.register(OptionalNestedClass.class, tmpl2);
|
CustomMessage.register(OptionalNestedClass.class, tmpl2);
|
||||||
Template tmpl = new OptionalTemplate(DynamicTemplate.create(OptionalBaseClass.class));
|
Template tmpl = new NullableTemplate(DynamicTemplate.create(OptionalBaseClass.class));
|
||||||
CustomMessage.register(OptionalBaseClass.class, tmpl);
|
CustomMessage.register(OptionalBaseClass.class, tmpl);
|
||||||
OptionalBaseClass src = null;
|
OptionalBaseClass src = null;
|
||||||
ByteArrayOutputStream out = new ByteArrayOutputStream();
|
ByteArrayOutputStream out = new ByteArrayOutputStream();
|
||||||
@ -1287,7 +1287,7 @@ public class TestPackUnpack extends TestCase {
|
|||||||
.create(BaseClass2.class));
|
.create(BaseClass2.class));
|
||||||
packer.pack(new Packer(out), src);
|
packer.pack(new Packer(out), src);
|
||||||
ByteArrayInputStream in = new ByteArrayInputStream(out.toByteArray());
|
ByteArrayInputStream in = new ByteArrayInputStream(out.toByteArray());
|
||||||
Template tmpl = new OptionalTemplate(DynamicTemplate
|
Template tmpl = new NullableTemplate(DynamicTemplate
|
||||||
.create(BaseClass2.class));
|
.create(BaseClass2.class));
|
||||||
BaseClass2 dst = (BaseClass2) tmpl.unpack(new Unpacker(in));
|
BaseClass2 dst = (BaseClass2) tmpl.unpack(new Unpacker(in));
|
||||||
assertEquals(src, dst);
|
assertEquals(src, dst);
|
||||||
@ -1350,7 +1350,7 @@ public class TestPackUnpack extends TestCase {
|
|||||||
.create(OptionalBaseClass2.class));
|
.create(OptionalBaseClass2.class));
|
||||||
packer.pack(new Packer(out), src);
|
packer.pack(new Packer(out), src);
|
||||||
ByteArrayInputStream in = new ByteArrayInputStream(out.toByteArray());
|
ByteArrayInputStream in = new ByteArrayInputStream(out.toByteArray());
|
||||||
Template tmpl = new OptionalTemplate(DynamicTemplate
|
Template tmpl = new NullableTemplate(DynamicTemplate
|
||||||
.create(OptionalBaseClass2.class));
|
.create(OptionalBaseClass2.class));
|
||||||
OptionalBaseClass2 dst = (OptionalBaseClass2) tmpl.unpack(new Unpacker(
|
OptionalBaseClass2 dst = (OptionalBaseClass2) tmpl.unpack(new Unpacker(
|
||||||
in));
|
in));
|
||||||
@ -1411,7 +1411,7 @@ public class TestPackUnpack extends TestCase {
|
|||||||
.create(SampleSubClass.class));
|
.create(SampleSubClass.class));
|
||||||
packer.pack(new Packer(out), src);
|
packer.pack(new Packer(out), src);
|
||||||
ByteArrayInputStream in = new ByteArrayInputStream(out.toByteArray());
|
ByteArrayInputStream in = new ByteArrayInputStream(out.toByteArray());
|
||||||
Template tmpl = new OptionalTemplate(DynamicTemplate
|
Template tmpl = new NullableTemplate(DynamicTemplate
|
||||||
.create(SampleSubClass.class));
|
.create(SampleSubClass.class));
|
||||||
SampleSubClass dst = (SampleSubClass) tmpl.unpack(new Unpacker(in));
|
SampleSubClass dst = (SampleSubClass) tmpl.unpack(new Unpacker(in));
|
||||||
assertEquals(src, dst);
|
assertEquals(src, dst);
|
||||||
@ -1477,7 +1477,7 @@ public class TestPackUnpack extends TestCase {
|
|||||||
.create(SampleOptionalSubClass.class));
|
.create(SampleOptionalSubClass.class));
|
||||||
packer.pack(new Packer(out), src);
|
packer.pack(new Packer(out), src);
|
||||||
ByteArrayInputStream in = new ByteArrayInputStream(out.toByteArray());
|
ByteArrayInputStream in = new ByteArrayInputStream(out.toByteArray());
|
||||||
Template tmpl = new OptionalTemplate(DynamicTemplate
|
Template tmpl = new NullableTemplate(DynamicTemplate
|
||||||
.create(SampleOptionalSubClass.class));
|
.create(SampleOptionalSubClass.class));
|
||||||
SampleOptionalSubClass dst = (SampleOptionalSubClass) tmpl
|
SampleOptionalSubClass dst = (SampleOptionalSubClass) tmpl
|
||||||
.unpack(new Unpacker(in));
|
.unpack(new Unpacker(in));
|
||||||
@ -1545,7 +1545,7 @@ public class TestPackUnpack extends TestCase {
|
|||||||
.create(BaseMessagePackableUnpackableClass.class));
|
.create(BaseMessagePackableUnpackableClass.class));
|
||||||
packer.pack(new Packer(out), src);
|
packer.pack(new Packer(out), src);
|
||||||
ByteArrayInputStream in = new ByteArrayInputStream(out.toByteArray());
|
ByteArrayInputStream in = new ByteArrayInputStream(out.toByteArray());
|
||||||
Template tmpl = new OptionalTemplate(DynamicTemplate
|
Template tmpl = new NullableTemplate(DynamicTemplate
|
||||||
.create(BaseMessagePackableUnpackableClass.class));
|
.create(BaseMessagePackableUnpackableClass.class));
|
||||||
BaseMessagePackableUnpackableClass dst = (BaseMessagePackableUnpackableClass) tmpl
|
BaseMessagePackableUnpackableClass dst = (BaseMessagePackableUnpackableClass) tmpl
|
||||||
.unpack(new Unpacker(in));
|
.unpack(new Unpacker(in));
|
||||||
@ -1644,7 +1644,7 @@ public class TestPackUnpack extends TestCase {
|
|||||||
.create(OptionalBaseMessagePackableUnpackableClass.class));
|
.create(OptionalBaseMessagePackableUnpackableClass.class));
|
||||||
packer.pack(new Packer(out), src);
|
packer.pack(new Packer(out), src);
|
||||||
ByteArrayInputStream in = new ByteArrayInputStream(out.toByteArray());
|
ByteArrayInputStream in = new ByteArrayInputStream(out.toByteArray());
|
||||||
Template tmpl = new OptionalTemplate(DynamicTemplate
|
Template tmpl = new NullableTemplate(DynamicTemplate
|
||||||
.create(OptionalBaseMessagePackableUnpackableClass.class));
|
.create(OptionalBaseMessagePackableUnpackableClass.class));
|
||||||
OptionalBaseMessagePackableUnpackableClass dst = (OptionalBaseMessagePackableUnpackableClass) tmpl
|
OptionalBaseMessagePackableUnpackableClass dst = (OptionalBaseMessagePackableUnpackableClass) tmpl
|
||||||
.unpack(new Unpacker(in));
|
.unpack(new Unpacker(in));
|
||||||
|
@ -19,6 +19,7 @@ import org.msgpack.packer.OptionalPacker;
|
|||||||
import org.msgpack.template.ListTemplate;
|
import org.msgpack.template.ListTemplate;
|
||||||
import org.msgpack.template.MapTemplate;
|
import org.msgpack.template.MapTemplate;
|
||||||
import org.msgpack.template.OptionalTemplate;
|
import org.msgpack.template.OptionalTemplate;
|
||||||
|
import org.msgpack.template.NullableTemplate;
|
||||||
import static org.msgpack.Templates.tBigInteger;
|
import static org.msgpack.Templates.tBigInteger;
|
||||||
import static org.msgpack.Templates.tBoolean;
|
import static org.msgpack.Templates.tBoolean;
|
||||||
import static org.msgpack.Templates.tByte;
|
import static org.msgpack.Templates.tByte;
|
||||||
@ -118,7 +119,7 @@ public class TestPackUnpackWithFieldOption extends TestCase {
|
|||||||
PrimitiveTypeFieldsClass.class, opts));
|
PrimitiveTypeFieldsClass.class, opts));
|
||||||
packer.pack(new Packer(out), src);
|
packer.pack(new Packer(out), src);
|
||||||
ByteArrayInputStream in = new ByteArrayInputStream(out.toByteArray());
|
ByteArrayInputStream in = new ByteArrayInputStream(out.toByteArray());
|
||||||
Template tmpl = new OptionalTemplate(DynamicTemplate.create(
|
Template tmpl = new NullableTemplate(DynamicTemplate.create(
|
||||||
PrimitiveTypeFieldsClass.class, opts));
|
PrimitiveTypeFieldsClass.class, opts));
|
||||||
PrimitiveTypeFieldsClass dst = (PrimitiveTypeFieldsClass) tmpl
|
PrimitiveTypeFieldsClass dst = (PrimitiveTypeFieldsClass) tmpl
|
||||||
.unpack(new Unpacker(in));
|
.unpack(new Unpacker(in));
|
||||||
@ -252,7 +253,7 @@ public class TestPackUnpackWithFieldOption extends TestCase {
|
|||||||
.create(GeneralReferenceTypeFieldsClass.class, opts));
|
.create(GeneralReferenceTypeFieldsClass.class, opts));
|
||||||
packer.pack(new Packer(out), src);
|
packer.pack(new Packer(out), src);
|
||||||
ByteArrayInputStream in = new ByteArrayInputStream(out.toByteArray());
|
ByteArrayInputStream in = new ByteArrayInputStream(out.toByteArray());
|
||||||
Template tmpl = new OptionalTemplate(DynamicTemplate
|
Template tmpl = new NullableTemplate(DynamicTemplate
|
||||||
.create(GeneralReferenceTypeFieldsClass.class, opts));
|
.create(GeneralReferenceTypeFieldsClass.class, opts));
|
||||||
GeneralReferenceTypeFieldsClass dst = (GeneralReferenceTypeFieldsClass) tmpl
|
GeneralReferenceTypeFieldsClass dst = (GeneralReferenceTypeFieldsClass) tmpl
|
||||||
.unpack(new Unpacker(in));
|
.unpack(new Unpacker(in));
|
||||||
@ -382,7 +383,7 @@ public class TestPackUnpackWithFieldOption extends TestCase {
|
|||||||
.create(SampleListTypes.class));
|
.create(SampleListTypes.class));
|
||||||
packer.pack(new Packer(out), src);
|
packer.pack(new Packer(out), src);
|
||||||
ByteArrayInputStream in = new ByteArrayInputStream(out.toByteArray());
|
ByteArrayInputStream in = new ByteArrayInputStream(out.toByteArray());
|
||||||
Template tmpl = new OptionalTemplate(DynamicTemplate
|
Template tmpl = new NullableTemplate(DynamicTemplate
|
||||||
.create(SampleListTypes.class));
|
.create(SampleListTypes.class));
|
||||||
SampleListTypes dst = (SampleListTypes) tmpl.unpack(new Unpacker(in));
|
SampleListTypes dst = (SampleListTypes) tmpl.unpack(new Unpacker(in));
|
||||||
assertEquals(src, dst);
|
assertEquals(src, dst);
|
||||||
@ -491,7 +492,7 @@ public class TestPackUnpackWithFieldOption extends TestCase {
|
|||||||
.create(SampleMapTypes.class, opts));
|
.create(SampleMapTypes.class, opts));
|
||||||
packer.pack(new Packer(out), src);
|
packer.pack(new Packer(out), src);
|
||||||
ByteArrayInputStream in = new ByteArrayInputStream(out.toByteArray());
|
ByteArrayInputStream in = new ByteArrayInputStream(out.toByteArray());
|
||||||
Template tmpl = new OptionalTemplate(DynamicTemplate
|
Template tmpl = new NullableTemplate(DynamicTemplate
|
||||||
.create(SampleMapTypes.class, opts));
|
.create(SampleMapTypes.class, opts));
|
||||||
SampleMapTypes dst = (SampleMapTypes) tmpl
|
SampleMapTypes dst = (SampleMapTypes) tmpl
|
||||||
.unpack(new Unpacker(in));
|
.unpack(new Unpacker(in));
|
||||||
|
Loading…
x
Reference in New Issue
Block a user