mirror of
https://github.com/msgpack/msgpack-c.git
synced 2025-10-22 16:02:30 +02:00
java: delete ByteBufferTemplate.java in org.msgpack.util.codegen package
This commit is contained in:
@@ -22,7 +22,6 @@ import org.msgpack.template.*;
|
||||
public class Templates {
|
||||
public static void load() { }
|
||||
|
||||
|
||||
public static Template tNullable(Template elementTemplate) {
|
||||
return new NullableTemplate(elementTemplate);
|
||||
}
|
||||
@@ -50,7 +49,6 @@ public class Templates {
|
||||
return new ClassTemplate(target);
|
||||
}
|
||||
|
||||
|
||||
public static final Template TByte = ByteTemplate.getInstance();
|
||||
public static Template tByte() {
|
||||
return TByte;
|
||||
@@ -101,5 +99,9 @@ public class Templates {
|
||||
return TByteArray;
|
||||
}
|
||||
|
||||
public static final Template TByteBuffer = ByteBufferTemplate.getInstance();
|
||||
public static Template tByteBuffer() {
|
||||
return TByteBuffer;
|
||||
}
|
||||
}
|
||||
|
||||
|
@@ -1,53 +0,0 @@
|
||||
package org.msgpack.util.codegen;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.nio.ByteBuffer;
|
||||
|
||||
import org.msgpack.CustomMessage;
|
||||
import org.msgpack.MessagePackObject;
|
||||
import org.msgpack.MessageTypeException;
|
||||
import org.msgpack.Packer;
|
||||
import org.msgpack.Template;
|
||||
import org.msgpack.Unpacker;
|
||||
|
||||
public class ByteBufferTemplate implements Template {
|
||||
private ByteBufferTemplate() {
|
||||
}
|
||||
|
||||
public void pack(Packer pk, Object target) throws IOException {
|
||||
byte[] bytes = byteBufferToByteArray((ByteBuffer) target);
|
||||
pk.packByteArray(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[] b = from.asByteArray();
|
||||
return ByteBuffer.wrap(b);
|
||||
}
|
||||
|
||||
private static byte[] byteBufferToByteArray(ByteBuffer b) {
|
||||
if (b.hasArray() && b.position() == 0 && b.arrayOffset() == 0
|
||||
&& b.remaining() == b.capacity()) {
|
||||
return b.array();
|
||||
} else {
|
||||
int len = b.remaining();
|
||||
byte[] ret = new byte[len];
|
||||
System.arraycopy(b.array(), b.arrayOffset() + b.position(), ret, 0, len);
|
||||
return ret;
|
||||
}
|
||||
}
|
||||
|
||||
static public ByteBufferTemplate getInstance() {
|
||||
return instance;
|
||||
}
|
||||
|
||||
static final ByteBufferTemplate instance = new ByteBufferTemplate();
|
||||
|
||||
static {
|
||||
CustomMessage.register(ByteBuffer.class, instance);
|
||||
}
|
||||
}
|
@@ -23,6 +23,7 @@ import java.lang.reflect.Constructor;
|
||||
import java.lang.reflect.Field;
|
||||
import java.lang.reflect.Modifier;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Collection;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.concurrent.ConcurrentHashMap;
|
||||
@@ -257,7 +258,8 @@ class DynamicCodeGen extends DynamicCodeGenBase implements Constants {
|
||||
Template createTemplate(Field field) {
|
||||
Class<?> c = field.getType();
|
||||
Template tmpl = null;
|
||||
if (List.class.isAssignableFrom(c) || Map.class.isAssignableFrom(c)) {
|
||||
if (List.class.isAssignableFrom(c) || Map.class.isAssignableFrom(c)
|
||||
|| Collection.class.isAssignableFrom(c)) {
|
||||
tmpl = createTemplate(field.getGenericType());
|
||||
} else {
|
||||
tmpl = createTemplate(c);
|
||||
|
@@ -25,6 +25,7 @@ import java.lang.reflect.ParameterizedType;
|
||||
import java.lang.reflect.Type;
|
||||
import java.math.BigInteger;
|
||||
import java.nio.ByteBuffer;
|
||||
import java.util.Collection;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.concurrent.atomic.AtomicInteger;
|
||||
@@ -318,8 +319,8 @@ public class DynamicCodeGenBase implements Constants {
|
||||
return Templates.tString();
|
||||
} else if (c.equals(BigInteger.class)) {
|
||||
return Templates.tBigInteger();
|
||||
} else if (c.equals(ByteBuffer.class)) {// FIXME
|
||||
return ByteBufferTemplate.getInstance();
|
||||
} else if (c.equals(ByteBuffer.class)) {
|
||||
return Templates.tByteBuffer();
|
||||
} else if (CustomConverter.isRegistered(c)) {// FIXME
|
||||
return (Template) CustomConverter.get(c);
|
||||
} else if (CustomMessage.isAnnotated(c, MessagePackMessage.class)) {
|
||||
@@ -363,8 +364,10 @@ public class DynamicCodeGenBase implements Constants {
|
||||
return Templates.tList(createTemplate(ats[0]));
|
||||
} else if (rawType.equals(Map.class)) {
|
||||
Type[] ats = pt.getActualTypeArguments();
|
||||
return Templates.tMap(createTemplate(ats[0]),
|
||||
createTemplate(ats[1]));
|
||||
return Templates.tMap(createTemplate(ats[0]), createTemplate(ats[1]));
|
||||
} else if (rawType.equals(Collection.class)) {
|
||||
Type[] ats = pt.getActualTypeArguments();
|
||||
return Templates.tCollection(createTemplate(ats[0]));
|
||||
} else {
|
||||
throw new DynamicCodeGenException("Type error: "
|
||||
+ t.getClass().getName());
|
||||
|
Reference in New Issue
Block a user