json
This commit is contained in:
@@ -324,7 +324,9 @@ public class InnerCoderEntity {
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public InnerCoderEntity convertFrom(Reader in) {
|
public InnerCoderEntity convertFrom(Reader in) {
|
||||||
if (in.readObjectB(InnerCoderEntity.class) == null) return null;
|
if (!in.readObjectB(this)) {
|
||||||
|
return null;
|
||||||
|
}
|
||||||
int index = 0;
|
int index = 0;
|
||||||
final Object[] params = new Object[deMembers.length];
|
final Object[] params = new Object[deMembers.length];
|
||||||
while (in.hasNext()) {
|
while (in.hasNext()) {
|
||||||
@@ -336,7 +338,7 @@ public class InnerCoderEntity {
|
|||||||
params[index++] = member.read(in);
|
params[index++] = member.read(in);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
in.readObjectE(InnerCoderEntity.class);
|
in.readObjectE();
|
||||||
return InnerCoderEntity.create(params[0] == null ? 0 : (Integer) params[0], (String) params[1]);
|
return InnerCoderEntity.create(params[0] == null ? 0 : (Integer) params[0], (String) params[1]);
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|||||||
@@ -90,19 +90,12 @@ public class ArrayDecoder<R extends Reader, T> implements Decodeable<R, T[]> {
|
|||||||
public T[] convertFrom(R in) {
|
public T[] convertFrom(R in) {
|
||||||
this.checkInited();
|
this.checkInited();
|
||||||
final Decodeable<R, T> itemDecoder = this.componentDecoder;
|
final Decodeable<R, T> itemDecoder = this.componentDecoder;
|
||||||
int len = in.readArrayB(itemDecoder);
|
if (!in.readArrayB(itemDecoder)) {
|
||||||
if (len == Reader.SIGN_NULL) {
|
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
final List<T> result = new ArrayList();
|
final List<T> result = new ArrayList();
|
||||||
if (len == Reader.SIGN_VARIABLE) {
|
while (in.hasNext()) {
|
||||||
while (in.hasNext()) {
|
result.add(itemDecoder.convertFrom(in));
|
||||||
result.add(itemDecoder.convertFrom(in));
|
|
||||||
}
|
|
||||||
} else { // 固定长度
|
|
||||||
for (int i = 0; i < len; i++) {
|
|
||||||
result.add(itemDecoder.convertFrom(in));
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
in.readArrayE();
|
in.readArrayE();
|
||||||
T[] rs = this.componentArrayFunction.apply(result.size());
|
T[] rs = this.componentArrayFunction.apply(result.size());
|
||||||
|
|||||||
@@ -95,19 +95,12 @@ public class CollectionDecoder<R extends Reader, T> implements Decodeable<R, Col
|
|||||||
public Collection<T> convertFrom(R in) {
|
public Collection<T> convertFrom(R in) {
|
||||||
this.checkInited();
|
this.checkInited();
|
||||||
final Decodeable<R, T> itemDecoder = this.componentDecoder;
|
final Decodeable<R, T> itemDecoder = this.componentDecoder;
|
||||||
int size = in.readArrayB(itemDecoder);
|
if (!in.readArrayB(itemDecoder)) {
|
||||||
if (size == Reader.SIGN_NULL) {
|
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
final Collection<T> result = this.creator.create();
|
final Collection<T> result = this.creator.create();
|
||||||
if (size == Reader.SIGN_VARIABLE) {
|
while (in.hasNext()) {
|
||||||
while (in.hasNext()) {
|
result.add(itemDecoder.convertFrom(in));
|
||||||
result.add(itemDecoder.convertFrom(in));
|
|
||||||
}
|
|
||||||
} else { // 固定长度
|
|
||||||
for (int i = 0; i < size; i++) {
|
|
||||||
result.add(itemDecoder.convertFrom(in));
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
in.readArrayE();
|
in.readArrayE();
|
||||||
return result;
|
return result;
|
||||||
|
|||||||
@@ -118,25 +118,15 @@ public class MapDecoder<R extends Reader, K, V> implements Decodeable<R, Map<K,
|
|||||||
this.checkInited();
|
this.checkInited();
|
||||||
Decodeable<R, K> kdecoder = this.keyDecoder;
|
Decodeable<R, K> kdecoder = this.keyDecoder;
|
||||||
Decodeable<R, V> vdecoder = this.valueDecoder;
|
Decodeable<R, V> vdecoder = this.valueDecoder;
|
||||||
int len = in.readMapB(kdecoder, vdecoder);
|
if (!in.readMapB(kdecoder, vdecoder)) {
|
||||||
if (len == Reader.SIGN_NULL) {
|
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
final Map<K, V> result = this.creator.create();
|
final Map<K, V> result = this.creator.create();
|
||||||
if (len == Reader.SIGN_VARIABLE) {
|
while (in.hasNext()) {
|
||||||
while (in.hasNext()) {
|
K key = kdecoder.convertFrom(in);
|
||||||
K key = kdecoder.convertFrom(in);
|
in.readColon();
|
||||||
in.readColon();
|
V value = vdecoder.convertFrom(in);
|
||||||
V value = vdecoder.convertFrom(in);
|
result.put(key, value);
|
||||||
result.put(key, value);
|
|
||||||
}
|
|
||||||
} else { // 固定长度
|
|
||||||
for (int i = 0; i < len; i++) {
|
|
||||||
K key = kdecoder.convertFrom(in);
|
|
||||||
in.readColon();
|
|
||||||
V value = vdecoder.convertFrom(in);
|
|
||||||
result.put(key, value);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
in.readMapE();
|
in.readMapE();
|
||||||
return result;
|
return result;
|
||||||
|
|||||||
@@ -360,8 +360,7 @@ public class ObjectDecoder<R extends Reader, T> implements Decodeable<R, T> {
|
|||||||
@Override
|
@Override
|
||||||
public T convertFrom(final R in) {
|
public T convertFrom(final R in) {
|
||||||
this.checkInited();
|
this.checkInited();
|
||||||
final String clazz = in.readObjectB(typeClass);
|
if (!in.readObjectB(this)) {
|
||||||
if (clazz == null) {
|
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
if (this.creator == null) {
|
if (this.creator == null) {
|
||||||
@@ -384,7 +383,7 @@ public class ObjectDecoder<R extends Reader, T> implements Decodeable<R, T> {
|
|||||||
member.getAttribute().set(result, val);
|
member.getAttribute().set(result, val);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
in.readObjectE(typeClass);
|
in.readObjectE();
|
||||||
return result;
|
return result;
|
||||||
} else { // 带参数的构造函数
|
} else { // 带参数的构造函数
|
||||||
final DeMember<R, T, ?>[] constructorFields = this.creatorConstructorMembers;
|
final DeMember<R, T, ?>[] constructorFields = this.creatorConstructorMembers;
|
||||||
@@ -411,7 +410,7 @@ public class ObjectDecoder<R extends Reader, T> implements Decodeable<R, T> {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
in.readObjectE(typeClass);
|
in.readObjectE();
|
||||||
if (this.creator == null) {
|
if (this.creator == null) {
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -16,20 +16,6 @@ import org.redkale.annotation.Nullable;
|
|||||||
*/
|
*/
|
||||||
public abstract class Reader {
|
public abstract class Reader {
|
||||||
|
|
||||||
/**
|
|
||||||
* 集合对象为null
|
|
||||||
*
|
|
||||||
* @see #readArrayB(org.redkale.convert.Decodeable)
|
|
||||||
*/
|
|
||||||
public static final short SIGN_NULL = -1;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* 不确定的长度, 比如解析json数组
|
|
||||||
*
|
|
||||||
* @see #readArrayB(org.redkale.convert.Decodeable)
|
|
||||||
*/
|
|
||||||
public static final short SIGN_VARIABLE = -2;
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 设置Reader的内容,通常结合对象池使用
|
* 设置Reader的内容,通常结合对象池使用
|
||||||
*
|
*
|
||||||
@@ -62,32 +48,26 @@ public abstract class Reader {
|
|||||||
public abstract void readColon();
|
public abstract void readColon();
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 读取对象的类名, 返回 null 表示对象为null, 返回空字符串表示当前class与返回的class一致,返回非空字符串表示class是当前class的子类。
|
* 读取对象,返回false表示对象为null
|
||||||
*
|
*
|
||||||
* @param clazz 类名
|
* @param decoder Decodeable
|
||||||
*
|
* @return 是否存在对象
|
||||||
* @return 返回字段数
|
|
||||||
*/
|
*/
|
||||||
public String readObjectB(final Class clazz) {
|
public abstract boolean readObjectB(final Decodeable decoder);
|
||||||
return null;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 读取对象的尾端
|
* 读取对象的尾端
|
||||||
*
|
*
|
||||||
* @param clazz 类名
|
|
||||||
*/
|
*/
|
||||||
public abstract void readObjectE(final Class clazz);
|
public abstract void readObjectE();
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 读取数组的开头并返回数组的长度
|
* 读取数组,返回false表示数组为null
|
||||||
*
|
*
|
||||||
* @see #SIGN_NULL
|
|
||||||
* @see #SIGN_VARIABLE
|
|
||||||
* @param componentDecoder Decodeable
|
* @param componentDecoder Decodeable
|
||||||
* @return 返回数组的长度
|
* @return 是否存在对象
|
||||||
*/
|
*/
|
||||||
public abstract int readArrayB(@Nullable Decodeable componentDecoder);
|
public abstract boolean readArrayB(@Nullable Decodeable componentDecoder);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 读取数组的尾端
|
* 读取数组的尾端
|
||||||
@@ -95,13 +75,13 @@ public abstract class Reader {
|
|||||||
public abstract void readArrayE();
|
public abstract void readArrayE();
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 读取map的开头并返回map的size
|
* 读取map,返回false表示map为null
|
||||||
*
|
*
|
||||||
* @param keyDecoder Decodeable
|
* @param keyDecoder Decodeable
|
||||||
* @param valueDecoder Decodeable
|
* @param valueDecoder Decodeable
|
||||||
* @return 返回map的size
|
* @return 是否存在对象
|
||||||
*/
|
*/
|
||||||
public abstract int readMapB(Decodeable keyDecoder, Decodeable valueDecoder);
|
public abstract boolean readMapB(Decodeable keyDecoder, Decodeable valueDecoder);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 读取Map的尾端
|
* 读取Map的尾端
|
||||||
|
|||||||
@@ -80,19 +80,12 @@ public class StreamDecoder<R extends Reader, T> implements Decodeable<R, Stream<
|
|||||||
public Stream<T> convertFrom(R in) {
|
public Stream<T> convertFrom(R in) {
|
||||||
this.checkInited();
|
this.checkInited();
|
||||||
final Decodeable<R, T> itemDecoder = this.componentDecoder;
|
final Decodeable<R, T> itemDecoder = this.componentDecoder;
|
||||||
int len = in.readArrayB(itemDecoder);
|
if (!in.readArrayB(itemDecoder)) {
|
||||||
if (len == Reader.SIGN_NULL) {
|
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
final List<T> result = new ArrayList();
|
final List<T> result = new ArrayList();
|
||||||
if (len == Reader.SIGN_VARIABLE) {
|
while (in.hasNext()) {
|
||||||
while (in.hasNext()) {
|
result.add(itemDecoder.convertFrom(in));
|
||||||
result.add(itemDecoder.convertFrom(in));
|
|
||||||
}
|
|
||||||
} else { // 固定长度
|
|
||||||
for (int i = 0; i < len; i++) {
|
|
||||||
result.add(itemDecoder.convertFrom(in));
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
in.readArrayE();
|
in.readArrayE();
|
||||||
return result.stream();
|
return result.stream();
|
||||||
|
|||||||
@@ -40,32 +40,22 @@ public final class BoolArraySimpledCoder<R extends Reader, W extends Writer> ext
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public boolean[] convertFrom(R in) {
|
public boolean[] convertFrom(R in) {
|
||||||
int len = in.readArrayB(BoolSimpledCoder.instance);
|
if (!in.readArrayB(BoolSimpledCoder.instance)) {
|
||||||
if (len == Reader.SIGN_NULL) {
|
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
if (len == Reader.SIGN_VARIABLE) {
|
int size = 0;
|
||||||
int size = 0;
|
boolean[] data = new boolean[8];
|
||||||
boolean[] data = new boolean[8];
|
while (in.hasNext()) {
|
||||||
while (in.hasNext()) {
|
if (size >= data.length) {
|
||||||
if (size >= data.length) {
|
boolean[] newdata = new boolean[data.length + 4];
|
||||||
boolean[] newdata = new boolean[data.length + 4];
|
System.arraycopy(data, 0, newdata, 0, size);
|
||||||
System.arraycopy(data, 0, newdata, 0, size);
|
data = newdata;
|
||||||
data = newdata;
|
|
||||||
}
|
|
||||||
data[size++] = in.readBoolean();
|
|
||||||
}
|
}
|
||||||
in.readArrayE();
|
data[size++] = in.readBoolean();
|
||||||
boolean[] newdata = new boolean[size];
|
|
||||||
System.arraycopy(data, 0, newdata, 0, size);
|
|
||||||
return newdata;
|
|
||||||
} else {
|
|
||||||
boolean[] values = new boolean[len];
|
|
||||||
for (int i = 0; i < values.length; i++) {
|
|
||||||
values[i] = in.readBoolean();
|
|
||||||
}
|
|
||||||
in.readArrayE();
|
|
||||||
return values;
|
|
||||||
}
|
}
|
||||||
|
in.readArrayE();
|
||||||
|
boolean[] newdata = new boolean[size];
|
||||||
|
System.arraycopy(data, 0, newdata, 0, size);
|
||||||
|
return newdata;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -41,30 +41,20 @@ public final class ByteBufferSimpledCoder<R extends Reader, W extends Writer> ex
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public ByteBuffer convertFrom(R in) {
|
public ByteBuffer convertFrom(R in) {
|
||||||
int len = in.readArrayB(ByteSimpledCoder.instance);
|
if (!in.readArrayB(ByteSimpledCoder.instance)) {
|
||||||
if (len == Reader.SIGN_NULL) {
|
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
if (len == Reader.SIGN_VARIABLE) {
|
int size = 0;
|
||||||
int size = 0;
|
byte[] data = new byte[8];
|
||||||
byte[] data = new byte[8];
|
while (in.hasNext()) {
|
||||||
while (in.hasNext()) {
|
if (size >= data.length) {
|
||||||
if (size >= data.length) {
|
byte[] newdata = new byte[data.length + 4];
|
||||||
byte[] newdata = new byte[data.length + 4];
|
System.arraycopy(data, 0, newdata, 0, size);
|
||||||
System.arraycopy(data, 0, newdata, 0, size);
|
data = newdata;
|
||||||
data = newdata;
|
|
||||||
}
|
|
||||||
data[size++] = in.readByte();
|
|
||||||
}
|
}
|
||||||
in.readArrayE();
|
data[size++] = in.readByte();
|
||||||
return ByteBuffer.wrap(data, 0, size);
|
|
||||||
} else {
|
|
||||||
byte[] values = new byte[len];
|
|
||||||
for (int i = 0; i < values.length; i++) {
|
|
||||||
values[i] = in.readByte();
|
|
||||||
}
|
|
||||||
in.readArrayE();
|
|
||||||
return ByteBuffer.wrap(values);
|
|
||||||
}
|
}
|
||||||
|
in.readArrayE();
|
||||||
|
return ByteBuffer.wrap(data, 0, size);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -40,32 +40,22 @@ public final class CharArraySimpledCoder<R extends Reader, W extends Writer> ext
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public char[] convertFrom(R in) {
|
public char[] convertFrom(R in) {
|
||||||
int len = in.readArrayB(CharSimpledCoder.instance);
|
if (!in.readArrayB(CharSimpledCoder.instance)) {
|
||||||
if (len == Reader.SIGN_NULL) {
|
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
if (len == Reader.SIGN_VARIABLE) {
|
int size = 0;
|
||||||
int size = 0;
|
char[] data = new char[8];
|
||||||
char[] data = new char[8];
|
while (in.hasNext()) {
|
||||||
while (in.hasNext()) {
|
if (size >= data.length) {
|
||||||
if (size >= data.length) {
|
char[] newdata = new char[data.length + 4];
|
||||||
char[] newdata = new char[data.length + 4];
|
System.arraycopy(data, 0, newdata, 0, size);
|
||||||
System.arraycopy(data, 0, newdata, 0, size);
|
data = newdata;
|
||||||
data = newdata;
|
|
||||||
}
|
|
||||||
data[size++] = in.readChar();
|
|
||||||
}
|
}
|
||||||
in.readArrayE();
|
data[size++] = in.readChar();
|
||||||
char[] newdata = new char[size];
|
|
||||||
System.arraycopy(data, 0, newdata, 0, size);
|
|
||||||
return newdata;
|
|
||||||
} else {
|
|
||||||
char[] values = new char[len];
|
|
||||||
for (int i = 0; i < values.length; i++) {
|
|
||||||
values[i] = in.readChar();
|
|
||||||
}
|
|
||||||
in.readArrayE();
|
|
||||||
return values;
|
|
||||||
}
|
}
|
||||||
|
in.readArrayE();
|
||||||
|
char[] newdata = new char[size];
|
||||||
|
System.arraycopy(data, 0, newdata, 0, size);
|
||||||
|
return newdata;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -29,7 +29,7 @@ public final class CompletionHandlerSimpledCoder<R extends Reader, W extends Wri
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public CompletionHandler convertFrom(R in) {
|
public CompletionHandler convertFrom(R in) {
|
||||||
in.readObjectB(CompletionHandler.class);
|
in.readObjectB(this);
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -41,33 +41,23 @@ public final class DoubleArraySimpledCoder<R extends Reader, W extends Writer> e
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public double[] convertFrom(R in) {
|
public double[] convertFrom(R in) {
|
||||||
int len = in.readArrayB(DoubleSimpledCoder.instance);
|
if (!in.readArrayB(DoubleSimpledCoder.instance)) {
|
||||||
if (len == Reader.SIGN_NULL) {
|
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
if (len == Reader.SIGN_VARIABLE) {
|
int size = 0;
|
||||||
int size = 0;
|
double[] data = new double[8];
|
||||||
double[] data = new double[8];
|
while (in.hasNext()) {
|
||||||
while (in.hasNext()) {
|
if (size >= data.length) {
|
||||||
if (size >= data.length) {
|
double[] newdata = new double[data.length + 4];
|
||||||
double[] newdata = new double[data.length + 4];
|
System.arraycopy(data, 0, newdata, 0, size);
|
||||||
System.arraycopy(data, 0, newdata, 0, size);
|
data = newdata;
|
||||||
data = newdata;
|
|
||||||
}
|
|
||||||
data[size++] = in.readDouble();
|
|
||||||
}
|
}
|
||||||
in.readArrayE();
|
data[size++] = in.readDouble();
|
||||||
double[] newdata = new double[size];
|
|
||||||
System.arraycopy(data, 0, newdata, 0, size);
|
|
||||||
return newdata;
|
|
||||||
} else {
|
|
||||||
double[] values = new double[len];
|
|
||||||
for (int i = 0; i < values.length; i++) {
|
|
||||||
values[i] = in.readDouble();
|
|
||||||
}
|
|
||||||
in.readArrayE();
|
|
||||||
return values;
|
|
||||||
}
|
}
|
||||||
|
in.readArrayE();
|
||||||
|
double[] newdata = new double[size];
|
||||||
|
System.arraycopy(data, 0, newdata, 0, size);
|
||||||
|
return newdata;
|
||||||
}
|
}
|
||||||
|
|
||||||
public static final class DoubleStreamSimpledCoder<R extends Reader, W extends Writer>
|
public static final class DoubleStreamSimpledCoder<R extends Reader, W extends Writer>
|
||||||
|
|||||||
@@ -40,32 +40,22 @@ public final class FloatArraySimpledCoder<R extends Reader, W extends Writer> ex
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public float[] convertFrom(R in) {
|
public float[] convertFrom(R in) {
|
||||||
int len = in.readArrayB(FloatSimpledCoder.instance);
|
if (!in.readArrayB(FloatSimpledCoder.instance)) {
|
||||||
if (len == Reader.SIGN_NULL) {
|
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
if (len == Reader.SIGN_VARIABLE) {
|
int size = 0;
|
||||||
int size = 0;
|
float[] data = new float[8];
|
||||||
float[] data = new float[8];
|
while (in.hasNext()) {
|
||||||
while (in.hasNext()) {
|
if (size >= data.length) {
|
||||||
if (size >= data.length) {
|
float[] newdata = new float[data.length + 4];
|
||||||
float[] newdata = new float[data.length + 4];
|
System.arraycopy(data, 0, newdata, 0, size);
|
||||||
System.arraycopy(data, 0, newdata, 0, size);
|
data = newdata;
|
||||||
data = newdata;
|
|
||||||
}
|
|
||||||
data[size++] = in.readFloat();
|
|
||||||
}
|
}
|
||||||
in.readArrayE();
|
data[size++] = in.readFloat();
|
||||||
float[] newdata = new float[size];
|
|
||||||
System.arraycopy(data, 0, newdata, 0, size);
|
|
||||||
return newdata;
|
|
||||||
} else {
|
|
||||||
float[] values = new float[len];
|
|
||||||
for (int i = 0; i < values.length; i++) {
|
|
||||||
values[i] = in.readFloat();
|
|
||||||
}
|
|
||||||
in.readArrayE();
|
|
||||||
return values;
|
|
||||||
}
|
}
|
||||||
|
in.readArrayE();
|
||||||
|
float[] newdata = new float[size];
|
||||||
|
System.arraycopy(data, 0, newdata, 0, size);
|
||||||
|
return newdata;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -41,33 +41,23 @@ public final class IntArraySimpledCoder<R extends Reader, W extends Writer> exte
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public int[] convertFrom(R in) {
|
public int[] convertFrom(R in) {
|
||||||
int len = in.readArrayB(IntSimpledCoder.instance);
|
if (!in.readArrayB(IntSimpledCoder.instance)) {
|
||||||
if (len == Reader.SIGN_NULL) {
|
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
if (len == Reader.SIGN_VARIABLE) {
|
int size = 0;
|
||||||
int size = 0;
|
int[] data = new int[8];
|
||||||
int[] data = new int[8];
|
while (in.hasNext()) {
|
||||||
while (in.hasNext()) {
|
if (size >= data.length) {
|
||||||
if (size >= data.length) {
|
int[] newdata = new int[data.length + 4];
|
||||||
int[] newdata = new int[data.length + 4];
|
System.arraycopy(data, 0, newdata, 0, size);
|
||||||
System.arraycopy(data, 0, newdata, 0, size);
|
data = newdata;
|
||||||
data = newdata;
|
|
||||||
}
|
|
||||||
data[size++] = in.readInt();
|
|
||||||
}
|
}
|
||||||
in.readArrayE();
|
data[size++] = in.readInt();
|
||||||
int[] newdata = new int[size];
|
|
||||||
System.arraycopy(data, 0, newdata, 0, size);
|
|
||||||
return newdata;
|
|
||||||
} else {
|
|
||||||
int[] values = new int[len];
|
|
||||||
for (int i = 0; i < values.length; i++) {
|
|
||||||
values[i] = in.readInt();
|
|
||||||
}
|
|
||||||
in.readArrayE();
|
|
||||||
return values;
|
|
||||||
}
|
}
|
||||||
|
in.readArrayE();
|
||||||
|
int[] newdata = new int[size];
|
||||||
|
System.arraycopy(data, 0, newdata, 0, size);
|
||||||
|
return newdata;
|
||||||
}
|
}
|
||||||
|
|
||||||
public static final class IntStreamSimpledCoder<R extends Reader, W extends Writer>
|
public static final class IntStreamSimpledCoder<R extends Reader, W extends Writer>
|
||||||
|
|||||||
@@ -41,33 +41,23 @@ public final class LongArraySimpledCoder<R extends Reader, W extends Writer> ext
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public long[] convertFrom(R in) {
|
public long[] convertFrom(R in) {
|
||||||
int len = in.readArrayB(LongSimpledCoder.instance);
|
if (!in.readArrayB(LongSimpledCoder.instance)) {
|
||||||
if (len == Reader.SIGN_NULL) {
|
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
if (len == Reader.SIGN_VARIABLE) {
|
int size = 0;
|
||||||
int size = 0;
|
long[] data = new long[8];
|
||||||
long[] data = new long[8];
|
while (in.hasNext()) {
|
||||||
while (in.hasNext()) {
|
if (size >= data.length) {
|
||||||
if (size >= data.length) {
|
long[] newdata = new long[data.length + 4];
|
||||||
long[] newdata = new long[data.length + 4];
|
System.arraycopy(data, 0, newdata, 0, size);
|
||||||
System.arraycopy(data, 0, newdata, 0, size);
|
data = newdata;
|
||||||
data = newdata;
|
|
||||||
}
|
|
||||||
data[size++] = in.readLong();
|
|
||||||
}
|
}
|
||||||
in.readArrayE();
|
data[size++] = in.readLong();
|
||||||
long[] newdata = new long[size];
|
|
||||||
System.arraycopy(data, 0, newdata, 0, size);
|
|
||||||
return newdata;
|
|
||||||
} else {
|
|
||||||
long[] values = new long[len];
|
|
||||||
for (int i = 0; i < values.length; i++) {
|
|
||||||
values[i] = in.readLong();
|
|
||||||
}
|
|
||||||
in.readArrayE();
|
|
||||||
return values;
|
|
||||||
}
|
}
|
||||||
|
in.readArrayE();
|
||||||
|
long[] newdata = new long[size];
|
||||||
|
System.arraycopy(data, 0, newdata, 0, size);
|
||||||
|
return newdata;
|
||||||
}
|
}
|
||||||
|
|
||||||
public static final class LongStreamSimpledCoder<R extends Reader, W extends Writer>
|
public static final class LongStreamSimpledCoder<R extends Reader, W extends Writer>
|
||||||
|
|||||||
@@ -40,32 +40,22 @@ public final class ShortArraySimpledCoder<R extends Reader, W extends Writer> ex
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public short[] convertFrom(R in) {
|
public short[] convertFrom(R in) {
|
||||||
int len = in.readArrayB(ShortSimpledCoder.instance);
|
if (!in.readArrayB(ShortSimpledCoder.instance)) {
|
||||||
if (len == Reader.SIGN_NULL) {
|
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
if (len == Reader.SIGN_VARIABLE) {
|
int size = 0;
|
||||||
int size = 0;
|
short[] data = new short[8];
|
||||||
short[] data = new short[8];
|
while (in.hasNext()) {
|
||||||
while (in.hasNext()) {
|
if (size >= data.length) {
|
||||||
if (size >= data.length) {
|
short[] newdata = new short[data.length + 4];
|
||||||
short[] newdata = new short[data.length + 4];
|
System.arraycopy(data, 0, newdata, 0, size);
|
||||||
System.arraycopy(data, 0, newdata, 0, size);
|
data = newdata;
|
||||||
data = newdata;
|
|
||||||
}
|
|
||||||
data[size++] = in.readShort();
|
|
||||||
}
|
}
|
||||||
in.readArrayE();
|
data[size++] = in.readShort();
|
||||||
short[] newdata = new short[size];
|
|
||||||
System.arraycopy(data, 0, newdata, 0, size);
|
|
||||||
return newdata;
|
|
||||||
} else {
|
|
||||||
short[] values = new short[len];
|
|
||||||
for (int i = 0; i < values.length; i++) {
|
|
||||||
values[i] = in.readShort();
|
|
||||||
}
|
|
||||||
in.readArrayE();
|
|
||||||
return values;
|
|
||||||
}
|
}
|
||||||
|
in.readArrayE();
|
||||||
|
short[] newdata = new short[size];
|
||||||
|
System.arraycopy(data, 0, newdata, 0, size);
|
||||||
|
return newdata;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -40,32 +40,22 @@ public final class StringArraySimpledCoder<R extends Reader, W extends Writer> e
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public String[] convertFrom(R in) {
|
public String[] convertFrom(R in) {
|
||||||
int len = in.readArrayB(StringSimpledCoder.instance);
|
if (!in.readArrayB(StringSimpledCoder.instance)) {
|
||||||
if (len == Reader.SIGN_NULL) {
|
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
if (len == Reader.SIGN_VARIABLE) {
|
int size = 0;
|
||||||
int size = 0;
|
String[] data = new String[8];
|
||||||
String[] data = new String[8];
|
while (in.hasNext()) {
|
||||||
while (in.hasNext()) {
|
if (size >= data.length) {
|
||||||
if (size >= data.length) {
|
String[] newdata = new String[data.length + 4];
|
||||||
String[] newdata = new String[data.length + 4];
|
System.arraycopy(data, 0, newdata, 0, size);
|
||||||
System.arraycopy(data, 0, newdata, 0, size);
|
data = newdata;
|
||||||
data = newdata;
|
|
||||||
}
|
|
||||||
data[size++] = in.readString();
|
|
||||||
}
|
}
|
||||||
in.readArrayE();
|
data[size++] = in.readString();
|
||||||
String[] newdata = new String[size];
|
|
||||||
System.arraycopy(data, 0, newdata, 0, size);
|
|
||||||
return newdata;
|
|
||||||
} else {
|
|
||||||
String[] values = new String[len];
|
|
||||||
for (int i = 0; i < values.length; i++) {
|
|
||||||
values[i] = in.readString();
|
|
||||||
}
|
|
||||||
in.readArrayE();
|
|
||||||
return values;
|
|
||||||
}
|
}
|
||||||
|
in.readArrayE();
|
||||||
|
String[] newdata = new String[size];
|
||||||
|
System.arraycopy(data, 0, newdata, 0, size);
|
||||||
|
return newdata;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -8,7 +8,6 @@ package org.redkale.convert.json;
|
|||||||
import java.nio.ByteBuffer;
|
import java.nio.ByteBuffer;
|
||||||
import java.nio.charset.UnmappableCharacterException;
|
import java.nio.charset.UnmappableCharacterException;
|
||||||
import org.redkale.convert.*;
|
import org.redkale.convert.*;
|
||||||
import static org.redkale.convert.Reader.*;
|
|
||||||
import org.redkale.util.ByteTreeNode;
|
import org.redkale.util.ByteTreeNode;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -170,42 +169,43 @@ public class JsonByteBufferReader extends JsonReader {
|
|||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 判断下一个非空白字符是否为{
|
* 读取对象,返回false表示对象为null
|
||||||
*
|
*
|
||||||
* @return SIGN_VARIABLE 或 SIGN_NULL
|
* @param decoder Decodeable
|
||||||
|
* @return 是否存在对象
|
||||||
*/
|
*/
|
||||||
@Override
|
@Override
|
||||||
public final String readObjectB(final Class clazz) {
|
public final boolean readObjectB(Decodeable decoder) {
|
||||||
char ch = nextGoodChar(true);
|
char ch = nextGoodChar(true);
|
||||||
if (ch == '{') {
|
if (ch == '{') {
|
||||||
return "";
|
return true;
|
||||||
}
|
}
|
||||||
if (ch == 'n' && nextChar() == 'u' && nextChar() == 'l' && nextChar() == 'l') {
|
if (ch == 'n' && nextChar() == 'u' && nextChar() == 'l' && nextChar() == 'l') {
|
||||||
return null;
|
return false;
|
||||||
}
|
}
|
||||||
if (ch == 'N' && nextChar() == 'U' && nextChar() == 'L' && nextChar() == 'L') {
|
if (ch == 'N' && nextChar() == 'U' && nextChar() == 'L' && nextChar() == 'L') {
|
||||||
return null;
|
return false;
|
||||||
}
|
}
|
||||||
throw new ConvertException("a json object must begin with '{' (position = " + position + ") but '" + ch + "'");
|
throw new ConvertException("a json object must begin with '{' (position = " + position + ") but '" + ch + "'");
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 判断下一个非空白字符是否为[
|
* 读取数组,返回false表示数组为null
|
||||||
*
|
*
|
||||||
* @param decoder Decodeable
|
* @param componentDecoder Decodeable
|
||||||
* @return SIGN_VARIABLE 或 SIGN_NULL
|
* @return 是否存在对象
|
||||||
*/
|
*/
|
||||||
@Override
|
@Override
|
||||||
public final int readArrayB(Decodeable decoder) {
|
public final boolean readArrayB(Decodeable componentDecoder) {
|
||||||
char ch = nextGoodChar(true);
|
char ch = nextGoodChar(true);
|
||||||
if (ch == '[' || ch == '{') {
|
if (ch == '[' || ch == '{') {
|
||||||
return SIGN_VARIABLE;
|
return true;
|
||||||
}
|
}
|
||||||
if (ch == 'n' && nextChar() == 'u' && nextChar() == 'l' && nextChar() == 'l') {
|
if (ch == 'n' && nextChar() == 'u' && nextChar() == 'l' && nextChar() == 'l') {
|
||||||
return SIGN_NULL;
|
return false;
|
||||||
}
|
}
|
||||||
if (ch == 'N' && nextChar() == 'U' && nextChar() == 'L' && nextChar() == 'L') {
|
if (ch == 'N' && nextChar() == 'U' && nextChar() == 'L' && nextChar() == 'L') {
|
||||||
return SIGN_NULL;
|
return false;
|
||||||
}
|
}
|
||||||
int pos = this.position;
|
int pos = this.position;
|
||||||
throw new ConvertException("a json array must begin with '[' (position = " + pos + ") but '" + ch + "'");
|
throw new ConvertException("a json array must begin with '[' (position = " + pos + ") but '" + ch + "'");
|
||||||
|
|||||||
@@ -35,8 +35,7 @@ public class JsonMultiArrayDecoder implements Decodeable<JsonReader, Object[]> {
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public Object[] convertFrom(JsonReader in) {
|
public Object[] convertFrom(JsonReader in) {
|
||||||
int len = in.readArrayB(null);
|
if (!in.readArrayB(null)) {
|
||||||
if (len == Reader.SIGN_NULL) {
|
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
// len must be Reader.SIGN_VARIABLE
|
// len must be Reader.SIGN_VARIABLE
|
||||||
|
|||||||
@@ -102,8 +102,7 @@ public class JsonMultiImplDecoder<T> implements Decodeable<JsonReader, T> {
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public T convertFrom(JsonReader in) {
|
public T convertFrom(JsonReader in) {
|
||||||
final String clazz = in.readObjectB(null);
|
if (!in.readObjectB(this)) {
|
||||||
if (clazz == null) {
|
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
ObjectDecoder decoder = this.firstDecoder;
|
ObjectDecoder decoder = this.firstDecoder;
|
||||||
@@ -150,7 +149,7 @@ public class JsonMultiImplDecoder<T> implements Decodeable<JsonReader, T> {
|
|||||||
params[++index] = new Object[] {member.getAttribute(), member.read(in)};
|
params[++index] = new Object[] {member.getAttribute(), member.read(in)};
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
in.readObjectE(null);
|
in.readObjectE();
|
||||||
if (decoder.getConstructorMembers() == null) { // 空构造函数
|
if (decoder.getConstructorMembers() == null) { // 空构造函数
|
||||||
T result = (T) decoder.getCreator().create();
|
T result = (T) decoder.getCreator().create();
|
||||||
for (int i = 0; i <= index; i++) {
|
for (int i = 0; i <= index; i++) {
|
||||||
|
|||||||
@@ -8,7 +8,6 @@ package org.redkale.convert.json;
|
|||||||
import java.nio.charset.StandardCharsets;
|
import java.nio.charset.StandardCharsets;
|
||||||
import java.util.*;
|
import java.util.*;
|
||||||
import org.redkale.convert.*;
|
import org.redkale.convert.*;
|
||||||
import static org.redkale.convert.Reader.*;
|
|
||||||
import org.redkale.util.ByteTreeNode;
|
import org.redkale.util.ByteTreeNode;
|
||||||
import org.redkale.util.Utility;
|
import org.redkale.util.Utility;
|
||||||
|
|
||||||
@@ -270,75 +269,58 @@ public class JsonReader extends Reader {
|
|||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 判断下一个非空白字符是否为{
|
* 读取对象,返回false表示对象为null
|
||||||
*
|
*
|
||||||
* @param clazz 类名
|
* @param decoder Decodeable
|
||||||
* @return 返回 null 表示对象为null, 返回空字符串表示当前class与返回的class一致,返回非空字符串表示class是当前class的子类。
|
* @return 是否存在对象
|
||||||
*/
|
*/
|
||||||
@Override
|
@Override
|
||||||
public String readObjectB(final Class clazz) {
|
public boolean readObjectB(final Decodeable decoder) {
|
||||||
if (this.text.length == 0) {
|
if (this.text.length == 0) {
|
||||||
return null;
|
return false;
|
||||||
}
|
}
|
||||||
char ch = nextGoodChar(true);
|
char ch = nextGoodChar(true);
|
||||||
if (ch == '{') {
|
if (ch == '{') {
|
||||||
return "";
|
return true;
|
||||||
}
|
}
|
||||||
if (ch == 'n' && text[++position] == 'u' && text[++position] == 'l' && text[++position] == 'l') {
|
if (ch == 'n' && text[++position] == 'u' && text[++position] == 'l' && text[++position] == 'l') {
|
||||||
return null;
|
return false;
|
||||||
}
|
}
|
||||||
if (ch == 'N' && text[++position] == 'U' && text[++position] == 'L' && text[++position] == 'L') {
|
if (ch == 'N' && text[++position] == 'U' && text[++position] == 'L' && text[++position] == 'L') {
|
||||||
return null;
|
return false;
|
||||||
}
|
}
|
||||||
throw new ConvertException("a json object must begin with '{' (position = " + position + ") but '" + ch
|
throw new ConvertException("a json object must begin with '{' (position = " + position + ") but '" + ch
|
||||||
+ "' in " + new String(this.text));
|
+ "' in " + new String(this.text));
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public final void readObjectE(final Class clazz) {
|
public final void readObjectE() {
|
||||||
// do nothing
|
// do nothing
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 判断下一个非空白字符是否为{
|
* 读取数组,返回false表示数组为null
|
||||||
*
|
|
||||||
* @param keyDecoder Decodeable
|
|
||||||
* @param valuedecoder Decodeable
|
|
||||||
* @return SIGN_VARIABLE 或 SIGN_NULL
|
|
||||||
*/
|
|
||||||
@Override
|
|
||||||
public final int readMapB(Decodeable keyDecoder, Decodeable valuedecoder) {
|
|
||||||
return readArrayB(keyDecoder);
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public final void readMapE() {
|
|
||||||
// do nothing
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* 判断下一个非空白字符是否为[
|
|
||||||
*
|
*
|
||||||
* @param componentDecoder Decodeable
|
* @param componentDecoder Decodeable
|
||||||
* @return SIGN_VARIABLE 或 SIGN_NULL
|
* @return 是否存在对象
|
||||||
*/
|
*/
|
||||||
@Override
|
@Override
|
||||||
public int readArrayB(Decodeable componentDecoder) {
|
public boolean readArrayB(Decodeable componentDecoder) {
|
||||||
if (this.text.length == 0) {
|
if (this.text.length == 0) {
|
||||||
return SIGN_NULL;
|
return false;
|
||||||
}
|
}
|
||||||
char ch = nextGoodChar(true);
|
char ch = nextGoodChar(true);
|
||||||
if (ch == '[') {
|
if (ch == '[') {
|
||||||
return SIGN_VARIABLE;
|
return true;
|
||||||
}
|
}
|
||||||
if (ch == '{') {
|
if (ch == '{') {
|
||||||
return SIGN_VARIABLE;
|
return true;
|
||||||
}
|
}
|
||||||
if (ch == 'n' && text[++position] == 'u' && text[++position] == 'l' && text[++position] == 'l') {
|
if (ch == 'n' && text[++position] == 'u' && text[++position] == 'l' && text[++position] == 'l') {
|
||||||
return SIGN_NULL;
|
return false;
|
||||||
}
|
}
|
||||||
if (ch == 'N' && text[++position] == 'U' && text[++position] == 'L' && text[++position] == 'L') {
|
if (ch == 'N' && text[++position] == 'U' && text[++position] == 'L' && text[++position] == 'L') {
|
||||||
return SIGN_NULL;
|
return false;
|
||||||
}
|
}
|
||||||
throw new ConvertException("a json array text must begin with '[' (position = " + position + ") but '" + ch
|
throw new ConvertException("a json array text must begin with '[' (position = " + position + ") but '" + ch
|
||||||
+ "' in " + new String(this.text));
|
+ "' in " + new String(this.text));
|
||||||
@@ -349,6 +331,23 @@ public class JsonReader extends Reader {
|
|||||||
// do nothing
|
// do nothing
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 读取map,返回false表示map为null
|
||||||
|
*
|
||||||
|
* @param keyDecoder Decodeable
|
||||||
|
* @param valueDecoder Decodeable
|
||||||
|
* @return 是否存在对象
|
||||||
|
*/
|
||||||
|
@Override
|
||||||
|
public final boolean readMapB(Decodeable keyDecoder, Decodeable valueDecoder) {
|
||||||
|
return readArrayB(keyDecoder);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public final void readMapE() {
|
||||||
|
// do nothing
|
||||||
|
}
|
||||||
|
|
||||||
/** 判断下一个非空白字符是否: */
|
/** 判断下一个非空白字符是否: */
|
||||||
@Override
|
@Override
|
||||||
public void readColon() {
|
public void readColon() {
|
||||||
@@ -720,33 +719,24 @@ public class JsonReader extends Reader {
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public final byte[] readByteArray() {
|
public final byte[] readByteArray() {
|
||||||
int len = readArrayB(null);
|
boolean has = readArrayB(null);
|
||||||
if (len == Reader.SIGN_NULL) {
|
if (!has) {
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
if (len == Reader.SIGN_VARIABLE) {
|
int size = 0;
|
||||||
int size = 0;
|
byte[] data = new byte[8];
|
||||||
byte[] data = new byte[8];
|
while (hasNext()) {
|
||||||
while (hasNext()) {
|
if (size >= data.length) {
|
||||||
if (size >= data.length) {
|
byte[] newdata = new byte[data.length + 4];
|
||||||
byte[] newdata = new byte[data.length + 4];
|
System.arraycopy(data, 0, newdata, 0, size);
|
||||||
System.arraycopy(data, 0, newdata, 0, size);
|
data = newdata;
|
||||||
data = newdata;
|
|
||||||
}
|
|
||||||
data[size++] = readByte();
|
|
||||||
}
|
}
|
||||||
readArrayE();
|
data[size++] = readByte();
|
||||||
byte[] newdata = new byte[size];
|
|
||||||
System.arraycopy(data, 0, newdata, 0, size);
|
|
||||||
return newdata;
|
|
||||||
} else { // 固定长度
|
|
||||||
byte[] values = new byte[len];
|
|
||||||
for (int i = 0; i < values.length; i++) {
|
|
||||||
values[i] = readByte();
|
|
||||||
}
|
|
||||||
readArrayE();
|
|
||||||
return values;
|
|
||||||
}
|
}
|
||||||
|
readArrayE();
|
||||||
|
byte[] newdata = new byte[size];
|
||||||
|
System.arraycopy(data, 0, newdata, 0, size);
|
||||||
|
return newdata;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
|||||||
@@ -110,22 +110,12 @@ public class ProtobufReader extends Reader {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public final String readObjectB(final Class clazz) {
|
public final boolean readObjectB(final Decodeable decoder) {
|
||||||
return hasNext() ? "" : null;
|
return hasNext();
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public final void readObjectE(final Class clazz) {
|
public final void readObjectE() {
|
||||||
// do nothing
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public final int readMapB(Decodeable keyDecoder, Decodeable valueDecoder) {
|
|
||||||
return Reader.SIGN_VARIABLE;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public final void readMapE() {
|
|
||||||
// do nothing
|
// do nothing
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -133,11 +123,11 @@ public class ProtobufReader extends Reader {
|
|||||||
* 判断下一个非空白字符是否为[
|
* 判断下一个非空白字符是否为[
|
||||||
*
|
*
|
||||||
* @param componentDecoder Decodeable
|
* @param componentDecoder Decodeable
|
||||||
* @return SIGN_VARIABLE 或 SIGN_NULL
|
* @return 是否存在对象
|
||||||
*/
|
*/
|
||||||
@Override
|
@Override
|
||||||
public final int readArrayB(Decodeable componentDecoder) {
|
public final boolean readArrayB(Decodeable componentDecoder) {
|
||||||
return Reader.SIGN_VARIABLE;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
@@ -145,6 +135,16 @@ public class ProtobufReader extends Reader {
|
|||||||
// do nothing
|
// do nothing
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public final boolean readMapB(Decodeable keyDecoder, Decodeable valueDecoder) {
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public final void readMapE() {
|
||||||
|
// do nothing
|
||||||
|
}
|
||||||
|
|
||||||
/** 判断下一个非空白字节是否: */
|
/** 判断下一个非空白字节是否: */
|
||||||
@Override
|
@Override
|
||||||
public final void readColon() {
|
public final void readColon() {
|
||||||
|
|||||||
@@ -106,7 +106,9 @@ public class InnerCoderEntityTest {
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public InnerCoderEntity convertFrom(Reader in) {
|
public InnerCoderEntity convertFrom(Reader in) {
|
||||||
if (in.readObjectB(InnerCoderEntity.class) == null) return null;
|
if (!in.readObjectB(this)) {
|
||||||
|
return null;
|
||||||
|
}
|
||||||
int index = 0;
|
int index = 0;
|
||||||
final Object[] params = new Object[deMembers.length];
|
final Object[] params = new Object[deMembers.length];
|
||||||
while (in.hasNext()) {
|
while (in.hasNext()) {
|
||||||
@@ -118,7 +120,7 @@ public class InnerCoderEntityTest {
|
|||||||
params[index++] = member.read(in);
|
params[index++] = member.read(in);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
in.readObjectE(InnerCoderEntity.class);
|
in.readObjectE();
|
||||||
return InnerCoderEntity.create(params[0] == null ? 0 : (Integer) params[0], (String) params[1]);
|
return InnerCoderEntity.create(params[0] == null ? 0 : (Integer) params[0], (String) params[1]);
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|||||||
Reference in New Issue
Block a user