mirror of
https://github.com/msgpack/msgpack-c.git
synced 2025-03-19 21:18:23 +01:00
java: fixes CustomMessage class
This commit is contained in:
parent
147056073d
commit
1bd347d997
@ -24,9 +24,18 @@ public class CustomMessage {
|
||||
CustomPacker.register(target, packer);
|
||||
}
|
||||
|
||||
public static void registerTemplate(Class<?> target, Template tmpl) {
|
||||
CustomUnpacker.register(target, tmpl);
|
||||
public static void registerConverter(Class<?> target, MessageConverter converter) {
|
||||
CustomConverter.register(target, converter);
|
||||
}
|
||||
|
||||
public static void registerUnpacker(Class<?> target, MessageUnpacker unpacker) {
|
||||
CustomUnpacker.register(target, unpacker);
|
||||
}
|
||||
|
||||
public static void register(Class<?> target, Template tmpl) {
|
||||
CustomPacker.register(target, tmpl);
|
||||
CustomConverter.register(target, tmpl);
|
||||
CustomUnpacker.register(target, tmpl);
|
||||
}
|
||||
|
||||
public static boolean isAnnotated(Class<?> target, Class<? extends Annotation> with) {
|
||||
|
@ -46,7 +46,7 @@ public class AnyTemplate implements Template {
|
||||
static final AnyTemplate instance = new AnyTemplate();
|
||||
|
||||
static {
|
||||
CustomMessage.registerTemplate(MessagePackObject.class, instance);
|
||||
CustomMessage.register(MessagePackObject.class, instance);
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -43,7 +43,7 @@ public class BigIntegerTemplate implements Template {
|
||||
static final BigIntegerTemplate instance = new BigIntegerTemplate();
|
||||
|
||||
static {
|
||||
CustomMessage.registerTemplate(BigInteger.class, instance);
|
||||
CustomMessage.register(BigInteger.class, instance);
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -42,7 +42,7 @@ public class BooleanTemplate implements Template {
|
||||
static final BooleanTemplate instance = new BooleanTemplate();
|
||||
|
||||
static {
|
||||
CustomMessage.registerTemplate(Boolean.class, instance);
|
||||
CustomMessage.register(Boolean.class, instance);
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -42,7 +42,7 @@ public class ByteArrayTemplate implements Template {
|
||||
static final ByteArrayTemplate instance = new ByteArrayTemplate();
|
||||
|
||||
static {
|
||||
CustomMessage.registerTemplate(byte[].class, instance);
|
||||
CustomMessage.register(byte[].class, instance);
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -42,7 +42,7 @@ public class ByteTemplate implements Template {
|
||||
static final ByteTemplate instance = new ByteTemplate();
|
||||
|
||||
static {
|
||||
CustomMessage.registerTemplate(Byte.class, instance);
|
||||
CustomMessage.register(Byte.class, instance);
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -42,7 +42,7 @@ public class DoubleTemplate implements Template {
|
||||
static final DoubleTemplate instance = new DoubleTemplate();
|
||||
|
||||
static {
|
||||
CustomMessage.registerTemplate(Double.class, instance);
|
||||
CustomMessage.register(Double.class, instance);
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -42,7 +42,7 @@ public class FloatTemplate implements Template {
|
||||
static final FloatTemplate instance = new FloatTemplate();
|
||||
|
||||
static {
|
||||
CustomMessage.registerTemplate(Float.class, instance);
|
||||
CustomMessage.register(Float.class, instance);
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -42,7 +42,7 @@ public class IntegerTemplate implements Template {
|
||||
static final IntegerTemplate instance = new IntegerTemplate();
|
||||
|
||||
static {
|
||||
CustomMessage.registerTemplate(Integer.class, instance);
|
||||
CustomMessage.register(Integer.class, instance);
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -42,7 +42,7 @@ public class LongTemplate implements Template {
|
||||
static final LongTemplate instance = new LongTemplate();
|
||||
|
||||
static {
|
||||
CustomMessage.registerTemplate(Long.class, instance);
|
||||
CustomMessage.register(Long.class, instance);
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -42,7 +42,7 @@ public class ShortTemplate implements Template {
|
||||
static final ShortTemplate instance = new ShortTemplate();
|
||||
|
||||
static {
|
||||
CustomMessage.registerTemplate(Short.class, instance);
|
||||
CustomMessage.register(Short.class, instance);
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -42,7 +42,7 @@ public class StringTemplate implements Template {
|
||||
static final StringTemplate instance = new StringTemplate();
|
||||
|
||||
static {
|
||||
CustomMessage.registerTemplate(String.class, instance);
|
||||
CustomMessage.register(String.class, instance);
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -581,7 +581,7 @@ public class DynamicCodeGenBase implements Constants {
|
||||
} else if (CustomMessage.isAnnotated(c, MessagePackMessage.class)) {
|
||||
// @MessagePackMessage
|
||||
Template tmpl = DynamicTemplate.create(c);
|
||||
CustomMessage.registerTemplate(c, tmpl);
|
||||
CustomMessage.register(c, tmpl);
|
||||
return tmpl;
|
||||
} else if (CustomMessage.isAnnotated(c, MessagePackDelegate.class)) {
|
||||
// FIXME DelegatePacker
|
||||
@ -593,12 +593,12 @@ public class DynamicCodeGenBase implements Constants {
|
||||
MessagePackOrdinalEnum.class)) {
|
||||
// @MessagePackOrdinalEnum
|
||||
Template tmpl = DynamicOrdinalEnumTemplate.create(c);
|
||||
CustomMessage.registerTemplate(c, tmpl);
|
||||
CustomMessage.register(c, tmpl);
|
||||
return tmpl;
|
||||
} else if (MessageConvertable.class.isAssignableFrom(c)
|
||||
|| MessageUnpackable.class.isAssignableFrom(c)) {
|
||||
Template tmpl = new MessageUnpackableConvertableTemplate(c);
|
||||
CustomMessage.registerTemplate(c, tmpl);
|
||||
CustomMessage.register(c, tmpl);
|
||||
return tmpl;
|
||||
} else {
|
||||
throw new MessageTypeException("Type error: "
|
||||
|
@ -72,20 +72,6 @@ public class TestMessagePackStaticMethods extends TestCase {
|
||||
byte[] e = MessagePack.pack(createProvidedClass(), tClass(ProvidedClass.class));
|
||||
byte[] f = MessagePack.pack(createUserDefinedClass(), tClass(UserDefinedClass.class));
|
||||
|
||||
{
|
||||
String aobj = MessagePack.unpack(a, String.class);
|
||||
Integer bobj = MessagePack.unpack(b, Integer.class);
|
||||
Object cobj = MessagePack.unpack(c, Object.class);
|
||||
ProvidedClass eobj = MessagePack.unpack(e, ProvidedClass.class);
|
||||
UserDefinedClass fobj = MessagePack.unpack(f, UserDefinedClass.class);
|
||||
|
||||
assertEquals(aobj, "msgpack");
|
||||
assertEquals(bobj, (Integer)1);
|
||||
assertEquals(cobj, null);
|
||||
assertEquals(eobj, createProvidedClass());
|
||||
assertEquals(fobj, createUserDefinedClass());
|
||||
}
|
||||
|
||||
{
|
||||
Object aobj = MessagePack.unpack(a, TString);
|
||||
Object bobj = MessagePack.unpack(b, TInteger);
|
||||
@ -103,6 +89,20 @@ public class TestMessagePackStaticMethods extends TestCase {
|
||||
assertEquals(eobj, createProvidedClass());
|
||||
assertEquals(fobj, createUserDefinedClass());
|
||||
}
|
||||
|
||||
{
|
||||
String aobj = MessagePack.unpack(a, String.class);
|
||||
Integer bobj = MessagePack.unpack(b, Integer.class);
|
||||
Object cobj = MessagePack.unpack(c, Object.class);
|
||||
ProvidedClass eobj = MessagePack.unpack(e, ProvidedClass.class);
|
||||
UserDefinedClass fobj = MessagePack.unpack(f, UserDefinedClass.class);
|
||||
|
||||
assertEquals(aobj, "msgpack");
|
||||
assertEquals(bobj, (Integer)1);
|
||||
assertEquals(cobj, null);
|
||||
assertEquals(eobj, createProvidedClass());
|
||||
assertEquals(fobj, createUserDefinedClass());
|
||||
}
|
||||
}
|
||||
|
||||
@Test
|
||||
@ -120,25 +120,6 @@ public class TestMessagePackStaticMethods extends TestCase {
|
||||
ByteArrayOutputStream fout = new ByteArrayOutputStream();
|
||||
MessagePack.pack(fout, createUserDefinedClass());
|
||||
|
||||
{
|
||||
InputStream ain = new ByteArrayInputStream(aout.toByteArray());
|
||||
String aobj = MessagePack.unpack(ain, String.class);
|
||||
InputStream bin = new ByteArrayInputStream(bout.toByteArray());
|
||||
Integer bobj = MessagePack.unpack(bin, Integer.class);
|
||||
InputStream cin = new ByteArrayInputStream(cout.toByteArray());
|
||||
Object cobj = MessagePack.unpack(cin, Object.class);
|
||||
InputStream ein = new ByteArrayInputStream(eout.toByteArray());
|
||||
ProvidedClass eobj = MessagePack.unpack(ein, ProvidedClass.class);
|
||||
InputStream fin = new ByteArrayInputStream(fout.toByteArray());
|
||||
UserDefinedClass fobj = MessagePack.unpack(fin, UserDefinedClass.class);
|
||||
|
||||
assertEquals(aobj, "msgpack");
|
||||
assertEquals(bobj, (Integer)1);
|
||||
assertEquals(cobj, null);
|
||||
assertEquals(eobj, createProvidedClass());
|
||||
assertEquals(fobj, createUserDefinedClass());
|
||||
}
|
||||
|
||||
{
|
||||
InputStream ain = new ByteArrayInputStream(aout.toByteArray());
|
||||
Object aobj = MessagePack.unpack(ain, TString);
|
||||
@ -163,6 +144,25 @@ public class TestMessagePackStaticMethods extends TestCase {
|
||||
assertEquals(eobj, createProvidedClass());
|
||||
assertEquals(fobj, createUserDefinedClass());
|
||||
}
|
||||
|
||||
{
|
||||
InputStream ain = new ByteArrayInputStream(aout.toByteArray());
|
||||
String aobj = MessagePack.unpack(ain, String.class);
|
||||
InputStream bin = new ByteArrayInputStream(bout.toByteArray());
|
||||
Integer bobj = MessagePack.unpack(bin, Integer.class);
|
||||
InputStream cin = new ByteArrayInputStream(cout.toByteArray());
|
||||
Object cobj = MessagePack.unpack(cin, Object.class);
|
||||
InputStream ein = new ByteArrayInputStream(eout.toByteArray());
|
||||
ProvidedClass eobj = MessagePack.unpack(ein, ProvidedClass.class);
|
||||
InputStream fin = new ByteArrayInputStream(fout.toByteArray());
|
||||
UserDefinedClass fobj = MessagePack.unpack(fin, UserDefinedClass.class);
|
||||
|
||||
assertEquals(aobj, "msgpack");
|
||||
assertEquals(bobj, (Integer)1);
|
||||
assertEquals(cobj, null);
|
||||
assertEquals(eobj, createProvidedClass());
|
||||
assertEquals(fobj, createUserDefinedClass());
|
||||
}
|
||||
}
|
||||
|
||||
@Test
|
||||
|
Loading…
x
Reference in New Issue
Block a user