mirror of
https://github.com/msgpack/msgpack-python.git
synced 2026-02-08 18:59:59 +00:00
java: MessagePackOptional -> Optional, MessagePackNullable -> Nullable
This commit is contained in:
parent
1135976225
commit
c283842563
8 changed files with 147 additions and 155 deletions
|
|
@ -22,6 +22,7 @@ import java.io.InputStream;
|
|||
import java.io.ByteArrayOutputStream;
|
||||
import java.io.IOException;
|
||||
import org.msgpack.util.codegen.DynamicTemplate;
|
||||
import org.msgpack.util.codegen.DynamicOrdinalEnumTemplate;
|
||||
import org.msgpack.util.codegen.FieldList;
|
||||
|
||||
public class MessagePack {
|
||||
|
|
@ -146,17 +147,18 @@ public class MessagePack {
|
|||
}
|
||||
|
||||
public static void register(Class<?> target) { // auto-detect
|
||||
// FIXME
|
||||
//Template tmpl;
|
||||
//if(List.isAssignableFrom(target)) {
|
||||
Template tmpl;
|
||||
if(target.isEnum()) {
|
||||
tmpl = DynamicOrdinalEnumTemplate.create(target);
|
||||
//} else if(List.isAssignableFrom(target)) {
|
||||
//} else if(Set.isAssignableFrom(target)) {
|
||||
//} else if(Map.isAssignableFrom(target)) {
|
||||
//} else if(Collection.isAssignableFrom(target)) {
|
||||
//} else if(BigInteger.isAssignableFrom(target)) {
|
||||
//} else {
|
||||
//}
|
||||
} else {
|
||||
tmpl = DynamicTemplate.create(target);
|
||||
}
|
||||
|
||||
Template tmpl = DynamicTemplate.create(target);
|
||||
CustomPacker.register(target, tmpl);
|
||||
CustomConverter.register(target, tmpl);
|
||||
CustomUnpacker.register(target, tmpl);
|
||||
|
|
|
|||
|
|
@ -24,5 +24,5 @@ import java.lang.annotation.Target;
|
|||
|
||||
@Target(ElementType.FIELD)
|
||||
@Retention(RetentionPolicy.RUNTIME)
|
||||
public @interface MessagePackNullable {
|
||||
public @interface Nullable {
|
||||
}
|
||||
|
|
@ -24,5 +24,5 @@ import java.lang.annotation.Target;
|
|||
|
||||
@Target(ElementType.FIELD)
|
||||
@Retention(RetentionPolicy.RUNTIME)
|
||||
public @interface MessagePackOptional {
|
||||
}
|
||||
public @interface Optional {
|
||||
}
|
||||
|
|
@ -22,9 +22,8 @@ import org.msgpack.*;
|
|||
import org.msgpack.annotation.MessagePackDelegate;
|
||||
import org.msgpack.annotation.MessagePackMessage;
|
||||
import org.msgpack.annotation.MessagePackOrdinalEnum;
|
||||
import org.msgpack.util.codegen.DynamicPacker;
|
||||
import org.msgpack.util.codegen.DynamicConverter;
|
||||
import org.msgpack.util.codegen.DynamicUnpacker;
|
||||
import org.msgpack.util.codegen.DynamicTemplate;
|
||||
import org.msgpack.util.codegen.DynamicOrdinalEnumTemplate;
|
||||
|
||||
import java.util.*;
|
||||
import java.math.BigInteger;
|
||||
|
|
@ -131,18 +130,17 @@ public class ClassTemplate implements Template {
|
|||
}
|
||||
|
||||
if (CustomMessage.isAnnotated(klass, MessagePackMessage.class)) {
|
||||
packer = DynamicPacker.create(klass);
|
||||
Template tmpl = DynamicTemplate.create(klass);
|
||||
CustomMessage.register(klass, tmpl);
|
||||
tmpl.pack(pk, o);
|
||||
return;
|
||||
} else if (CustomMessage.isAnnotated(klass, MessagePackDelegate.class)) {
|
||||
// FIXME DelegatePacker
|
||||
throw new UnsupportedOperationException("not supported yet. : " + klass.getName());
|
||||
} else if (CustomMessage.isAnnotated(klass, MessagePackOrdinalEnum.class)) {
|
||||
// FIXME OrdinalEnumPacker
|
||||
throw new UnsupportedOperationException("not supported yet. : " + klass.getName());
|
||||
}
|
||||
|
||||
if (packer != null) {
|
||||
CustomPacker.register(klass, packer);
|
||||
packer.pack(pk, o);
|
||||
Template tmpl = DynamicOrdinalEnumTemplate.create(klass);
|
||||
CustomMessage.register(klass, tmpl);
|
||||
tmpl.pack(pk, o);
|
||||
return;
|
||||
}
|
||||
|
||||
|
|
@ -169,38 +167,32 @@ public class ClassTemplate implements Template {
|
|||
}
|
||||
|
||||
if (CustomMessage.isAnnotated(klass, MessagePackMessage.class)) {
|
||||
unpacker = DynamicUnpacker.create(klass);
|
||||
Template tmpl = DynamicTemplate.create(klass);
|
||||
CustomMessage.register(klass, tmpl);
|
||||
return tmpl.unpack(pac, to);
|
||||
} else if (CustomMessage.isAnnotated(klass, MessagePackDelegate.class)) {
|
||||
// TODO DelegateUnpacker
|
||||
throw new UnsupportedOperationException("not supported yet. : " + klass.getName());
|
||||
} else if (CustomMessage.isAnnotated(klass, MessagePackOrdinalEnum.class)) {
|
||||
// TODO OrdinalEnumUnpacker
|
||||
throw new UnsupportedOperationException("not supported yet. : " + klass.getName());
|
||||
}
|
||||
|
||||
if (unpacker != null) {
|
||||
CustomUnpacker.register(klass, unpacker);
|
||||
return unpacker.unpack(pac, to);
|
||||
Template tmpl = DynamicOrdinalEnumTemplate.create(klass);
|
||||
CustomMessage.register(klass, tmpl);
|
||||
return tmpl.unpack(pac, to);
|
||||
}
|
||||
|
||||
// fallback
|
||||
{
|
||||
MessageConverter converter = null;
|
||||
MessageConverter converter = null;
|
||||
|
||||
if (CustomMessage.isAnnotated(klass, MessagePackMessage.class)) {
|
||||
converter = DynamicConverter.create(klass);
|
||||
} else if (CustomMessage.isAnnotated(klass, MessagePackDelegate.class)) {
|
||||
// TODO DelegateConverter
|
||||
throw new UnsupportedOperationException("not supported yet. : " + klass.getName());
|
||||
} else if (CustomMessage.isAnnotated(klass, MessagePackOrdinalEnum.class)) {
|
||||
// TODO OrdinalEnumConverter
|
||||
throw new UnsupportedOperationException("not supported yet. : " + klass.getName());
|
||||
}
|
||||
|
||||
if (converter != null) {
|
||||
CustomConverter.register(klass, converter);
|
||||
return converter.convert(pac.unpackObject(), to);
|
||||
}
|
||||
if (CustomMessage.isAnnotated(klass, MessagePackMessage.class)) {
|
||||
Template tmpl = DynamicTemplate.create(klass);
|
||||
CustomMessage.register(klass, tmpl);
|
||||
return tmpl.convert(pac.unpackObject(), to);
|
||||
} else if (CustomMessage.isAnnotated(klass, MessagePackDelegate.class)) {
|
||||
// TODO DelegateConverter
|
||||
throw new UnsupportedOperationException("not supported yet. : " + klass.getName());
|
||||
} else if (CustomMessage.isAnnotated(klass, MessagePackOrdinalEnum.class)) {
|
||||
Template tmpl = DynamicOrdinalEnumTemplate.create(klass);
|
||||
CustomMessage.register(klass, tmpl);
|
||||
return tmpl.convert(pac.unpackObject(), to);
|
||||
}
|
||||
|
||||
throw new MessageTypeException();
|
||||
|
|
@ -232,18 +224,16 @@ public class ClassTemplate implements Template {
|
|||
}
|
||||
|
||||
if (CustomMessage.isAnnotated(klass, MessagePackMessage.class)) {
|
||||
converter = DynamicConverter.create(klass);
|
||||
Template tmpl = DynamicTemplate.create(klass);
|
||||
CustomMessage.register(klass, tmpl);
|
||||
return tmpl.convert(from, to);
|
||||
} else if (CustomMessage.isAnnotated(klass, MessagePackDelegate.class)) {
|
||||
// TODO DelegateConverter
|
||||
throw new UnsupportedOperationException("not supported yet. : " + klass.getName());
|
||||
} else if (CustomMessage.isAnnotated(klass, MessagePackOrdinalEnum.class)) {
|
||||
// TODO OrdinalEnumConverter
|
||||
throw new UnsupportedOperationException("not supported yet. : " + klass.getName());
|
||||
}
|
||||
|
||||
if (converter != null) {
|
||||
CustomConverter.register(klass, converter);
|
||||
return converter.convert(from, to);
|
||||
Template tmpl = DynamicOrdinalEnumTemplate.create(klass);
|
||||
CustomMessage.register(klass, tmpl);
|
||||
return tmpl.convert(from, to);
|
||||
}
|
||||
|
||||
throw new MessageTypeException();
|
||||
|
|
|
|||
|
|
@ -39,8 +39,8 @@ import org.msgpack.MessageTypeException;
|
|||
import org.msgpack.Packer;
|
||||
import org.msgpack.Template;
|
||||
import org.msgpack.Unpacker;
|
||||
import org.msgpack.annotation.MessagePackOptional;
|
||||
import org.msgpack.annotation.MessagePackNullable;
|
||||
import org.msgpack.annotation.Optional;
|
||||
import org.msgpack.annotation.Nullable;
|
||||
import org.msgpack.template.OptionalTemplate;
|
||||
import org.msgpack.template.NullableTemplate;
|
||||
import org.slf4j.Logger;
|
||||
|
|
@ -290,11 +290,11 @@ class DynamicCodeGen extends DynamicCodeGenBase implements Constants {
|
|||
} else {
|
||||
tmpl = createTemplate(c);
|
||||
}
|
||||
if (isAnnotated(field, MessagePackOptional.class)) {
|
||||
if (isAnnotated(field, Optional.class)) {
|
||||
// @Optional types
|
||||
return new OptionalTemplate(tmpl);
|
||||
}
|
||||
if (!c.isPrimitive() && isAnnotated(field, MessagePackNullable.class)) {
|
||||
if (!c.isPrimitive() && isAnnotated(field, Nullable.class)) {
|
||||
// @Nullable reference types
|
||||
return new NullableTemplate(tmpl);
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue