java: @MessagePackMessage(default field option)

This commit is contained in:
FURUHASHI Sadayuki 2010-11-30 21:57:12 +09:00
parent 2c823f1aaa
commit d3a02fb2ca
8 changed files with 13 additions and 7 deletions

View File

@ -21,6 +21,7 @@ import java.io.OutputStream;
import java.io.InputStream;
import java.io.ByteArrayOutputStream;
import java.io.IOException;
import org.msgpack.buffer.VectoredByteBuffer;
import org.msgpack.util.codegen.DynamicTemplate;
import org.msgpack.util.codegen.DynamicOrdinalEnumTemplate;
import org.msgpack.util.codegen.FieldList;

View File

@ -155,7 +155,7 @@ public abstract class MessagePackObject implements Cloneable, MessagePackable {
return convert((Class<T>)to.getClass(), to);
}
private <T> T convert(Class<T> klass, T to) throws MessageTypeException {
public <T> T convert(Class<T> klass, T to) throws MessageTypeException {
// FIXME nullable?
return (T)convert(new NullableTemplate(new ClassTemplate(klass)), to);
}

View File

@ -27,5 +27,9 @@ public class MessageTypeException extends RuntimeException {
public MessageTypeException(String s, Throwable t) {
super(s, t);
}
public MessageTypeException(Throwable t) {
super(t);
}
}

View File

@ -25,4 +25,5 @@ import java.lang.annotation.Target;
@Target(ElementType.TYPE)
@Retention(RetentionPolicy.RUNTIME)
public @interface MessagePackDelegate {
String value();
}

View File

@ -21,8 +21,10 @@ import java.lang.annotation.ElementType;
import java.lang.annotation.Retention;
import java.lang.annotation.RetentionPolicy;
import java.lang.annotation.Target;
import org.msgpack.template.FieldOption;
@Target(ElementType.TYPE)
@Retention(RetentionPolicy.RUNTIME)
public @interface MessagePackMessage {
FieldOption value() default FieldOption.DEFAULT;
}

View File

@ -143,12 +143,8 @@ public class VectoredByteBuffer implements GatheringByteChannel, ScatteringByteC
// optimization: concatenates to the last buffer instead
// of adding new reference
ByteBuffer dup = vec.get(vec.size()-1);
int dpos = dup.position();
internalBuffer.put(b, off, len);
ByteBuffer dup2 = internalBuffer.duplicate();
dup2.position(dpos);
dup2.limit(ipos + len);
vec.set(vec.size()-1, dup2);
dup.limit(ipos + len);
return;
}
internalBuffer.put(b, off, len);

View File

@ -200,7 +200,7 @@ public class ClassTemplate implements Template {
return tmpl.convert(pac.unpackObject(), to);
}
throw new MessageTypeException();
throw new MessageTypeException("unknown type: "+klass);
} catch (IllegalAccessException e) {
throw new MessageTypeException(e.getMessage()); // FIXME

View File

@ -333,6 +333,8 @@ public class DynamicCodeGenBase implements Constants {
return Templates.tString();
} else if (c.equals(BigInteger.class)) {
return Templates.tBigInteger();
} else if (c.equals(byte[].class)) {
return Templates.tByteArray();
} else if (c.equals(ByteBuffer.class)) {
return Templates.tByteBuffer();
} else if (CustomConverter.isRegistered(c)) {// FIXME