This commit is contained in:
@@ -89,8 +89,9 @@ public class ArrayDecoder<T> implements Decodeable<Reader, T[]> {
|
||||
boolean first = true;
|
||||
if (len == Reader.SIGN_NOLENGTH) {
|
||||
int startPosition = in.position();
|
||||
while (in.hasNext(member, startPosition, contentLength)) {
|
||||
result.add(readMemberValue(in, member, first));
|
||||
while (in.hasNext(this, member, startPosition, contentLength)) {
|
||||
Reader itemReader = getArrayItemReader(in, member, first);
|
||||
result.add(readMemberValue(itemReader, member, first));
|
||||
first = false;
|
||||
}
|
||||
} else {
|
||||
@@ -103,6 +104,10 @@ public class ArrayDecoder<T> implements Decodeable<Reader, T[]> {
|
||||
return result.toArray(rs);
|
||||
}
|
||||
|
||||
protected Reader getArrayItemReader(Reader in, DeMember member, boolean first) {
|
||||
return in;
|
||||
}
|
||||
|
||||
protected T readMemberValue(Reader in, DeMember member, boolean first) {
|
||||
return this.decoder.convertFrom(in);
|
||||
}
|
||||
|
||||
@@ -89,7 +89,7 @@ public class CollectionDecoder<T> implements Decodeable<Reader, Collection<T>> {
|
||||
boolean first = true;
|
||||
if (len == Reader.SIGN_NOLENGTH) {
|
||||
int startPosition = in.position();
|
||||
while (in.hasNext(member, startPosition, contentLength)) {
|
||||
while (in.hasNext(this, member, startPosition, contentLength)) {
|
||||
result.add(readMemberValue(in, member, first));
|
||||
first = false;
|
||||
}
|
||||
|
||||
@@ -102,7 +102,7 @@ public class MapDecoder<K, V> implements Decodeable<Reader, Map<K, V>> {
|
||||
boolean first = true;
|
||||
if (len == Reader.SIGN_NOLENGTH) {
|
||||
int startPosition = in.position();
|
||||
while (in.hasNext(member, startPosition, contentLength)) {
|
||||
while (in.hasNext(this, member, startPosition, contentLength)) {
|
||||
Reader entryReader = getMapEntryReader(in, member, first);
|
||||
K key = readKeyMember(entryReader, member, first);
|
||||
entryReader.readBlank();
|
||||
|
||||
@@ -22,19 +22,20 @@ public abstract class Reader {
|
||||
|
||||
public static final short SIGN_NOLENGTH = -2;
|
||||
|
||||
public static final short SIGN_NOLENBUTBYTES = -3;
|
||||
public static final short SIGN_NOLENBUTBYTES = -3; //目前只适合于protobuf的boolean[]...double[]类型
|
||||
|
||||
/**
|
||||
* 是否还存在下个元素或字段 <br>
|
||||
* 注意: 主要用于Array、Collection、Stream或Map等集合对象
|
||||
*
|
||||
* @param self Decodeable
|
||||
* @param member DeMember
|
||||
* @param startPosition 起始位置
|
||||
* @param contentLength 内容大小, 不确定的传-1
|
||||
*
|
||||
* @return 是否还存在下个元素或字段
|
||||
*/
|
||||
public abstract boolean hasNext(DeMember member, int startPosition, int contentLength);
|
||||
public abstract boolean hasNext(Decodeable self, DeMember member, int startPosition, int contentLength);
|
||||
|
||||
/**
|
||||
* 是否还存在下个元素或字段
|
||||
@@ -43,7 +44,7 @@ public abstract class Reader {
|
||||
* @return 是否还存在下个元素或字段
|
||||
*/
|
||||
public boolean hasNext() {
|
||||
return hasNext(null, -1, -1);
|
||||
return hasNext(null, null, -1, -1);
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
@@ -85,7 +85,7 @@ public class StreamDecoder<T> implements Decodeable<Reader, Stream<T>> {
|
||||
boolean first = true;
|
||||
if (len == Reader.SIGN_NOLENGTH) {
|
||||
int startPosition = in.position();
|
||||
while (in.hasNext(member, startPosition, contentLength)) {
|
||||
while (in.hasNext(this, member, startPosition, contentLength)) {
|
||||
result.add(readMemberValue(in, member, first));
|
||||
first = false;
|
||||
}
|
||||
|
||||
@@ -215,13 +215,15 @@ public class BsonReader extends Reader {
|
||||
/**
|
||||
* 判断对象是否存在下一个属性或者数组是否存在下一个元素
|
||||
*
|
||||
* @param self Decodeable
|
||||
* @param member DeMember
|
||||
* @param startPosition 起始位置
|
||||
* @param contentLength 内容大小, 不确定的传-1
|
||||
*
|
||||
* @return 是否存在
|
||||
*/
|
||||
@Override
|
||||
public boolean hasNext(DeMember member, int startPosition, int contentLength) {
|
||||
public boolean hasNext(Decodeable self, DeMember member, int startPosition, int contentLength) {
|
||||
byte b = readByte();
|
||||
if (b == SIGN_HASNEXT) return true;
|
||||
if (b != SIGN_NONEXT) throw new ConvertException("hasNext option must be (" + (SIGN_HASNEXT)
|
||||
@@ -274,7 +276,7 @@ public class BsonReader extends Reader {
|
||||
int size = 0;
|
||||
byte[] data = new byte[8];
|
||||
int startPosition = position();
|
||||
while (hasNext(null, startPosition, contentLength)) {
|
||||
while (hasNext(null, null, startPosition, contentLength)) {
|
||||
if (size >= data.length) {
|
||||
byte[] newdata = new byte[data.length + 4];
|
||||
System.arraycopy(data, 0, newdata, 0, size);
|
||||
|
||||
@@ -53,7 +53,7 @@ public final class BoolArraySimpledCoder<R extends Reader, W extends Writer> ext
|
||||
int size = 0;
|
||||
boolean[] data = new boolean[8];
|
||||
int startPosition = in.position();
|
||||
while (in.hasNext(null, startPosition, contentLength)) {
|
||||
while (in.hasNext(this, null, startPosition, contentLength)) {
|
||||
if (size >= data.length) {
|
||||
boolean[] newdata = new boolean[data.length + 4];
|
||||
System.arraycopy(data, 0, newdata, 0, size);
|
||||
|
||||
@@ -54,7 +54,7 @@ public final class ByteBufferSimpledCoder<R extends Reader, W extends Writer> ex
|
||||
int size = 0;
|
||||
byte[] data = new byte[8];
|
||||
int startPosition = in.position();
|
||||
while (in.hasNext(null, startPosition, contentLength)) {
|
||||
while (in.hasNext(this, null, startPosition, contentLength)) {
|
||||
if (size >= data.length) {
|
||||
byte[] newdata = new byte[data.length + 4];
|
||||
System.arraycopy(data, 0, newdata, 0, size);
|
||||
|
||||
@@ -53,7 +53,7 @@ public final class CharArraySimpledCoder<R extends Reader, W extends Writer> ext
|
||||
int size = 0;
|
||||
char[] data = new char[8];
|
||||
int startPosition = in.position();
|
||||
while (in.hasNext(null, startPosition, contentLength)) {
|
||||
while (in.hasNext(this, null, startPosition, contentLength)) {
|
||||
if (size >= data.length) {
|
||||
char[] newdata = new char[data.length + 4];
|
||||
System.arraycopy(data, 0, newdata, 0, size);
|
||||
|
||||
@@ -54,7 +54,7 @@ public final class DoubleArraySimpledCoder<R extends Reader, W extends Writer> e
|
||||
int size = 0;
|
||||
double[] data = new double[8];
|
||||
int startPosition = in.position();
|
||||
while (in.hasNext(null, startPosition, contentLength)) {
|
||||
while (in.hasNext(this, null, startPosition, contentLength)) {
|
||||
if (size >= data.length) {
|
||||
double[] newdata = new double[data.length + 4];
|
||||
System.arraycopy(data, 0, newdata, 0, size);
|
||||
|
||||
@@ -53,7 +53,7 @@ public final class FloatArraySimpledCoder<R extends Reader, W extends Writer> ex
|
||||
int size = 0;
|
||||
float[] data = new float[8];
|
||||
int startPosition = in.position();
|
||||
while (in.hasNext(null, startPosition, contentLength)) {
|
||||
while (in.hasNext(this, null, startPosition, contentLength)) {
|
||||
if (size >= data.length) {
|
||||
float[] newdata = new float[data.length + 4];
|
||||
System.arraycopy(data, 0, newdata, 0, size);
|
||||
|
||||
@@ -54,7 +54,7 @@ public final class IntArraySimpledCoder<R extends Reader, W extends Writer> exte
|
||||
int size = 0;
|
||||
int[] data = new int[8];
|
||||
int startPosition = in.position();
|
||||
while (in.hasNext(null, startPosition, contentLength)) {
|
||||
while (in.hasNext(this, null, startPosition, contentLength)) {
|
||||
if (size >= data.length) {
|
||||
int[] newdata = new int[data.length + 4];
|
||||
System.arraycopy(data, 0, newdata, 0, size);
|
||||
|
||||
@@ -54,7 +54,7 @@ public final class LongArraySimpledCoder<R extends Reader, W extends Writer> ext
|
||||
int size = 0;
|
||||
long[] data = new long[8];
|
||||
int startPosition = in.position();
|
||||
while (in.hasNext(null, startPosition, contentLength)) {
|
||||
while (in.hasNext(this, null, startPosition, contentLength)) {
|
||||
if (size >= data.length) {
|
||||
long[] newdata = new long[data.length + 4];
|
||||
System.arraycopy(data, 0, newdata, 0, size);
|
||||
|
||||
@@ -53,7 +53,7 @@ public final class ShortArraySimpledCoder<R extends Reader, W extends Writer> ex
|
||||
int size = 0;
|
||||
short[] data = new short[8];
|
||||
int startPosition = in.position();
|
||||
while (in.hasNext(null, startPosition, contentLength)) {
|
||||
while (in.hasNext(this, null, startPosition, contentLength)) {
|
||||
if (size >= data.length) {
|
||||
short[] newdata = new short[data.length + 4];
|
||||
System.arraycopy(data, 0, newdata, 0, size);
|
||||
|
||||
@@ -55,7 +55,7 @@ public final class StringArraySimpledCoder<R extends Reader, W extends Writer> e
|
||||
int size = 0;
|
||||
String[] data = new String[8];
|
||||
int startPosition = in.position();
|
||||
while (in.hasNext(member, startPosition, contentLength)) {
|
||||
while (in.hasNext(this, member, startPosition, contentLength)) {
|
||||
if (size >= data.length) {
|
||||
String[] newdata = new String[data.length + 4];
|
||||
System.arraycopy(data, 0, newdata, 0, size);
|
||||
|
||||
@@ -159,6 +159,7 @@ public class JsonByteBufferReader extends JsonReader {
|
||||
/**
|
||||
* 判断对象是否存在下一个属性或者数组是否存在下一个元素
|
||||
*
|
||||
* @param self Decodeable
|
||||
* @param member DeMember
|
||||
* @param startPosition 起始位置
|
||||
* @param contentLength 内容大小, 不确定的传-1
|
||||
@@ -166,7 +167,7 @@ public class JsonByteBufferReader extends JsonReader {
|
||||
* @return 是否存在
|
||||
*/
|
||||
@Override
|
||||
public boolean hasNext(DeMember member, int startPosition, int contentLength) {
|
||||
public boolean hasNext(Decodeable self, DeMember member, int startPosition, int contentLength) {
|
||||
char ch = nextGoodChar();
|
||||
if (ch == ',') return true;
|
||||
if (ch == '}' || ch == ']' || ch == 0) return false;
|
||||
|
||||
@@ -263,13 +263,15 @@ public class JsonReader extends Reader {
|
||||
/**
|
||||
* 判断对象是否存在下一个属性或者数组是否存在下一个元素
|
||||
*
|
||||
* @param self Decodeable
|
||||
* @param member DeMember
|
||||
* @param startPosition 起始位置
|
||||
* @param contentLength 内容大小, 不确定的传-1
|
||||
*
|
||||
* @return 是否存在
|
||||
*/
|
||||
@Override
|
||||
public boolean hasNext(DeMember member, int startPosition, int contentLength) {
|
||||
public boolean hasNext(Decodeable self, DeMember member, int startPosition, int contentLength) {
|
||||
char ch = this.text[++this.position];
|
||||
if (ch == ',') return true;
|
||||
if (ch == '}' || ch == ']') return false;
|
||||
@@ -485,7 +487,7 @@ public class JsonReader extends Reader {
|
||||
int size = 0;
|
||||
byte[] data = new byte[8];
|
||||
int startPosition = position();
|
||||
while (hasNext(null, startPosition, contentLength)) {
|
||||
while (hasNext(null, null, startPosition, contentLength)) {
|
||||
if (size >= data.length) {
|
||||
byte[] newdata = new byte[data.length + 4];
|
||||
System.arraycopy(data, 0, newdata, 0, size);
|
||||
|
||||
Reference in New Issue
Block a user