更新Convert的Array、Map相关接口
This commit is contained in:
@@ -42,7 +42,7 @@ public final class AnyEncoder<T> implements Encodeable<Writer, T> {
|
||||
out.writeNull();
|
||||
} else {
|
||||
int count = values.length - values.length % 2;
|
||||
out.writeMapB(count / 2);
|
||||
out.writeMapB(count / 2, (Encodeable) this, (Encodeable) this, values);
|
||||
for (int i = 0; i < count; i += 2) {
|
||||
if (i > 0) out.writeArrayMark();
|
||||
this.convertTo(out, (T) values[i]);
|
||||
|
||||
@@ -62,8 +62,13 @@ public final class ArrayDecoder<T> implements Decodeable<Reader, T[]> {
|
||||
|
||||
@Override
|
||||
public T[] convertFrom(Reader in) {
|
||||
final int len = in.readArrayB();
|
||||
int len = in.readArrayB();
|
||||
int contentLength = -1;
|
||||
if (len == Reader.SIGN_NULL) return null;
|
||||
if (len == Reader.SIGN_NOLENBUTBYTES) {
|
||||
contentLength = in.readMemberContentLength();
|
||||
len = Reader.SIGN_NOLENGTH;
|
||||
}
|
||||
if (this.decoder == null) {
|
||||
if (!this.inited) {
|
||||
synchronized (lock) {
|
||||
@@ -78,7 +83,8 @@ public final class ArrayDecoder<T> implements Decodeable<Reader, T[]> {
|
||||
final Decodeable<Reader, T> localdecoder = this.decoder;
|
||||
final List<T> result = new ArrayList();
|
||||
if (len == Reader.SIGN_NOLENGTH) {
|
||||
while (in.hasNext()) {
|
||||
int startPosition = in.position();
|
||||
while (in.hasNext(startPosition, contentLength)) {
|
||||
result.add(localdecoder.convertFrom(in));
|
||||
}
|
||||
} else {
|
||||
|
||||
@@ -62,7 +62,7 @@ public final class ArrayEncoder<T> implements Encodeable<Writer, T[]> {
|
||||
return;
|
||||
}
|
||||
if (value.length == 0) {
|
||||
out.writeArrayB(0);
|
||||
out.writeArrayB(0, encoder, value);
|
||||
out.writeArrayE();
|
||||
return;
|
||||
}
|
||||
@@ -77,7 +77,7 @@ public final class ArrayEncoder<T> implements Encodeable<Writer, T[]> {
|
||||
}
|
||||
}
|
||||
}
|
||||
out.writeArrayB(value.length);
|
||||
out.writeArrayB(value.length, encoder, value);
|
||||
final Type comp = this.componentType;
|
||||
boolean first = true;
|
||||
for (Object v : value) {
|
||||
@@ -105,5 +105,5 @@ public final class ArrayEncoder<T> implements Encodeable<Writer, T[]> {
|
||||
public Encodeable<Writer, Object> getEncoder() {
|
||||
return encoder;
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
||||
@@ -44,7 +44,7 @@ public final class CollectionDecoder<T> implements Decodeable<Reader, Collection
|
||||
this.creator = factory.loadCreator((Class) pt.getRawType());
|
||||
factory.register(type, this);
|
||||
this.decoder = factory.loadDecoder(this.componentType);
|
||||
} else if(factory.isReversible()){
|
||||
} else if (factory.isReversible()) {
|
||||
this.componentType = Object.class;
|
||||
this.creator = factory.loadCreator(Object.class);
|
||||
factory.register(type, this);
|
||||
@@ -62,8 +62,13 @@ public final class CollectionDecoder<T> implements Decodeable<Reader, Collection
|
||||
|
||||
@Override
|
||||
public Collection<T> convertFrom(Reader in) {
|
||||
final int len = in.readArrayB();
|
||||
int len = in.readArrayB();
|
||||
int contentLength = -1;
|
||||
if (len == Reader.SIGN_NULL) return null;
|
||||
if (len == Reader.SIGN_NOLENBUTBYTES) {
|
||||
contentLength = in.readMemberContentLength();
|
||||
len = Reader.SIGN_NOLENGTH;
|
||||
}
|
||||
if (this.decoder == null) {
|
||||
if (!this.inited) {
|
||||
synchronized (lock) {
|
||||
@@ -78,7 +83,8 @@ public final class CollectionDecoder<T> implements Decodeable<Reader, Collection
|
||||
final Decodeable<Reader, T> localdecoder = this.decoder;
|
||||
final Collection<T> result = this.creator.create();
|
||||
if (len == Reader.SIGN_NOLENGTH) {
|
||||
while (in.hasNext()) {
|
||||
int startPosition = in.position();
|
||||
while (in.hasNext(startPosition, contentLength)) {
|
||||
result.add(localdecoder.convertFrom(in));
|
||||
}
|
||||
} else {
|
||||
|
||||
@@ -57,7 +57,7 @@ public final class CollectionEncoder<T> implements Encodeable<Writer, Collection
|
||||
return;
|
||||
}
|
||||
if (value.isEmpty()) {
|
||||
out.writeArrayB(0);
|
||||
out.writeArrayB(0, encoder, value);
|
||||
out.writeArrayE();
|
||||
return;
|
||||
}
|
||||
@@ -72,7 +72,7 @@ public final class CollectionEncoder<T> implements Encodeable<Writer, Collection
|
||||
}
|
||||
}
|
||||
}
|
||||
out.writeArrayB(value.size());
|
||||
out.writeArrayB(value.size(), encoder, value);
|
||||
boolean first = true;
|
||||
for (Object v : value) {
|
||||
if (!first) out.writeArrayMark();
|
||||
|
||||
@@ -87,11 +87,17 @@ public final class MapDecoder<K, V> implements Decodeable<Reader, Map<K, V>> {
|
||||
}
|
||||
}
|
||||
}
|
||||
final int len = in.readMapB();
|
||||
int len = in.readArrayB();
|
||||
int contentLength = -1;
|
||||
if (len == Reader.SIGN_NULL) return null;
|
||||
if (len == Reader.SIGN_NOLENBUTBYTES) {
|
||||
contentLength = in.readMemberContentLength();
|
||||
len = Reader.SIGN_NOLENGTH;
|
||||
}
|
||||
final Map<K, V> result = this.creator.create();
|
||||
if (len == Reader.SIGN_NOLENGTH) {
|
||||
while (in.hasNext()) {
|
||||
int startPosition = in.position();
|
||||
while (in.hasNext(startPosition, contentLength)) {
|
||||
K key = keyDecoder.convertFrom(in);
|
||||
in.readBlank();
|
||||
V value = valueDecoder.convertFrom(in);
|
||||
|
||||
@@ -70,7 +70,7 @@ public final class MapEncoder<K, V> implements Encodeable<Writer, Map<K, V>> {
|
||||
}
|
||||
}
|
||||
}
|
||||
out.writeMapB(values.size());
|
||||
out.writeMapB(values.size(), (Encodeable) keyencoder, (Encodeable) valencoder, value);
|
||||
boolean first = true;
|
||||
for (Map.Entry<K, V> en : values.entrySet()) {
|
||||
if (!first) out.writeArrayMark();
|
||||
@@ -94,5 +94,5 @@ public final class MapEncoder<K, V> implements Encodeable<Writer, Map<K, V>> {
|
||||
public Encodeable<Writer, V> getValencoder() {
|
||||
return valencoder;
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
||||
@@ -22,12 +22,43 @@ public abstract class Reader {
|
||||
|
||||
public static final short SIGN_NOLENGTH = -2;
|
||||
|
||||
public static final short SIGN_NOLENBUTBYTES = -3;
|
||||
|
||||
/**
|
||||
* 是否还存在下个元素或字段
|
||||
* 是否还存在下个元素或字段 <br>
|
||||
* 注意: 主要用于Array、Collection、Stream或Map等集合对象
|
||||
*
|
||||
* @param startPosition 起始位置
|
||||
* @param contentLength 内容大小, 不确定的传-1
|
||||
*
|
||||
* @return 是否还存在下个元素或字段
|
||||
*/
|
||||
public abstract boolean hasNext();
|
||||
public abstract boolean hasNext(int startPosition, int contentLength);
|
||||
|
||||
/**
|
||||
* 是否还存在下个元素或字段
|
||||
*
|
||||
*
|
||||
* @return 是否还存在下个元素或字段
|
||||
*/
|
||||
public boolean hasNext() {
|
||||
return hasNext(-1, -1);
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取当前位置
|
||||
*
|
||||
* @return 当前位置
|
||||
*/
|
||||
public abstract int position();
|
||||
|
||||
/**
|
||||
* 读取字段值内容的字节数 <br>
|
||||
* 只有在readXXXB方法返回SIGN_NOLENBUTBYTES值才会调用此方法
|
||||
*
|
||||
* @return 内容大小, 不确定返回-1
|
||||
*/
|
||||
public abstract int readMemberContentLength();
|
||||
|
||||
/**
|
||||
* 跳过值(不包含值前面的字段)
|
||||
|
||||
@@ -58,8 +58,13 @@ public final class StreamDecoder<T> implements Decodeable<Reader, Stream<T>> {
|
||||
|
||||
@Override
|
||||
public Stream<T> convertFrom(Reader in) {
|
||||
final int len = in.readArrayB();
|
||||
int len = in.readArrayB();
|
||||
int contentLength = -1;
|
||||
if (len == Reader.SIGN_NULL) return null;
|
||||
if (len == Reader.SIGN_NOLENBUTBYTES) {
|
||||
contentLength = in.readMemberContentLength();
|
||||
len = Reader.SIGN_NOLENGTH;
|
||||
}
|
||||
if (this.decoder == null) {
|
||||
if (!this.inited) {
|
||||
synchronized (lock) {
|
||||
@@ -74,7 +79,8 @@ public final class StreamDecoder<T> implements Decodeable<Reader, Stream<T>> {
|
||||
final Decodeable<Reader, T> localdecoder = this.decoder;
|
||||
final List<T> result = new ArrayList();
|
||||
if (len == Reader.SIGN_NOLENGTH) {
|
||||
while (in.hasNext()) {
|
||||
int startPosition = in.position();
|
||||
while (in.hasNext(startPosition, contentLength)) {
|
||||
result.add(localdecoder.convertFrom(in));
|
||||
}
|
||||
} else {
|
||||
|
||||
@@ -58,7 +58,7 @@ public final class StreamEncoder<T> implements Encodeable<Writer, Stream<T>> {
|
||||
}
|
||||
Object[] array = value.toArray();
|
||||
if (array.length == 0) {
|
||||
out.writeArrayB(0);
|
||||
out.writeArrayB(0, encoder, array);
|
||||
out.writeArrayE();
|
||||
return;
|
||||
}
|
||||
@@ -73,7 +73,7 @@ public final class StreamEncoder<T> implements Encodeable<Writer, Stream<T>> {
|
||||
}
|
||||
}
|
||||
}
|
||||
out.writeArrayB(array.length);
|
||||
out.writeArrayB(array.length, encoder, array);
|
||||
boolean first = true;
|
||||
for (Object v : array) {
|
||||
if (!first) out.writeArrayMark();
|
||||
@@ -91,5 +91,5 @@ public final class StreamEncoder<T> implements Encodeable<Writer, Stream<T>> {
|
||||
public Encodeable<Writer, Object> getEncoder() {
|
||||
return encoder;
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
||||
@@ -126,9 +126,11 @@ public abstract class Writer {
|
||||
/**
|
||||
* 输出一个数组前的操作
|
||||
*
|
||||
* @param size 数组长度
|
||||
* @param size 数组长度
|
||||
* @param encoder Encodeable
|
||||
* @param obj 对象
|
||||
*/
|
||||
public abstract void writeArrayB(int size);
|
||||
public abstract void writeArrayB(int size, Encodeable<Writer, Object> encoder, Object obj);
|
||||
|
||||
/**
|
||||
* 输出数组元素间的间隔符
|
||||
@@ -145,9 +147,12 @@ public abstract class Writer {
|
||||
/**
|
||||
* 输出一个Map前的操作
|
||||
*
|
||||
* @param size map大小
|
||||
* @param size map大小
|
||||
* @param keyEncoder Encodeable
|
||||
* @param valueEncoder Encodeable
|
||||
* @param obj 对象
|
||||
*/
|
||||
public abstract void writeMapB(int size);
|
||||
public abstract void writeMapB(int size, Encodeable<Writer, Object> keyEncoder, Encodeable<Writer, Object> valueEncoder, Object obj);
|
||||
|
||||
/**
|
||||
* 输出一个Map中key与value间的间隔符
|
||||
|
||||
@@ -202,13 +202,26 @@ public class BsonReader extends Reader {
|
||||
public final void readBlank() {
|
||||
}
|
||||
|
||||
@Override
|
||||
public int position() {
|
||||
return this.position;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int readMemberContentLength() {
|
||||
return -1;
|
||||
}
|
||||
|
||||
/**
|
||||
* 判断对象是否存在下一个属性或者数组是否存在下一个元素
|
||||
*
|
||||
* @param startPosition 起始位置
|
||||
* @param contentLength 内容大小, 不确定的传-1
|
||||
*
|
||||
* @return 是否存在
|
||||
*/
|
||||
@Override
|
||||
public final boolean hasNext() {
|
||||
public boolean hasNext(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)
|
||||
@@ -251,11 +264,17 @@ public class BsonReader extends Reader {
|
||||
@Override
|
||||
public final byte[] readByteArray() {
|
||||
int len = readArrayB();
|
||||
int contentLength = -1;
|
||||
if (len == Reader.SIGN_NULL) return null;
|
||||
if (len == Reader.SIGN_NOLENBUTBYTES) {
|
||||
contentLength = readMemberContentLength();
|
||||
len = Reader.SIGN_NOLENGTH;
|
||||
}
|
||||
if (len == Reader.SIGN_NOLENGTH) {
|
||||
int size = 0;
|
||||
byte[] data = new byte[8];
|
||||
while (hasNext()) {
|
||||
int startPosition = position();
|
||||
while (hasNext(startPosition, contentLength)) {
|
||||
if (size >= data.length) {
|
||||
byte[] newdata = new byte[data.length + 4];
|
||||
System.arraycopy(data, 0, newdata, 0, size);
|
||||
|
||||
@@ -131,7 +131,7 @@ public class BsonWriter extends Writer {
|
||||
writeNull();
|
||||
return;
|
||||
}
|
||||
writeArrayB(values.length);
|
||||
writeArrayB(values.length, null, values);
|
||||
boolean flag = false;
|
||||
for (byte v : values) {
|
||||
if (flag) writeArrayMark();
|
||||
@@ -284,7 +284,7 @@ public class BsonWriter extends Writer {
|
||||
}
|
||||
|
||||
@Override
|
||||
public final void writeArrayB(int size) {
|
||||
public final void writeArrayB(int size, Encodeable<Writer, Object> encoder, Object obj) {
|
||||
writeInt(size);
|
||||
}
|
||||
|
||||
@@ -297,8 +297,8 @@ public class BsonWriter extends Writer {
|
||||
}
|
||||
|
||||
@Override
|
||||
public void writeMapB(int size) {
|
||||
writeArrayB(size);
|
||||
public void writeMapB(int size, Encodeable<Writer, Object> keyEncoder, Encodeable<Writer, Object> valueEncoder, Object obj) {
|
||||
writeArrayB(size, valueEncoder, obj);
|
||||
}
|
||||
|
||||
@Override
|
||||
|
||||
@@ -29,7 +29,7 @@ public final class BoolArraySimpledCoder<R extends Reader, W extends Writer> ext
|
||||
out.writeNull();
|
||||
return;
|
||||
}
|
||||
out.writeArrayB(values.length);
|
||||
out.writeArrayB(values.length, BoolSimpledCoder.instance, values);
|
||||
boolean flag = false;
|
||||
for (boolean v : values) {
|
||||
if (flag) out.writeArrayMark();
|
||||
@@ -42,11 +42,17 @@ public final class BoolArraySimpledCoder<R extends Reader, W extends Writer> ext
|
||||
@Override
|
||||
public boolean[] convertFrom(R in) {
|
||||
int len = in.readArrayB();
|
||||
int contentLength = -1;
|
||||
if (len == Reader.SIGN_NULL) return null;
|
||||
if (len == Reader.SIGN_NOLENBUTBYTES) {
|
||||
contentLength = in.readMemberContentLength();
|
||||
len = Reader.SIGN_NOLENGTH;
|
||||
}
|
||||
if (len == Reader.SIGN_NOLENGTH) {
|
||||
int size = 0;
|
||||
boolean[] data = new boolean[8];
|
||||
while (in.hasNext()) {
|
||||
int startPosition = in.position();
|
||||
while (in.hasNext(startPosition, contentLength)) {
|
||||
if (size >= data.length) {
|
||||
boolean[] newdata = new boolean[data.length + 4];
|
||||
System.arraycopy(data, 0, newdata, 0, size);
|
||||
|
||||
@@ -30,7 +30,7 @@ public final class ByteBufferSimpledCoder<R extends Reader, W extends Writer> ex
|
||||
out.writeNull();
|
||||
return;
|
||||
}
|
||||
out.writeArrayB(value.remaining());
|
||||
out.writeArrayB(value.remaining(), ByteSimpledCoder.instance, value);
|
||||
boolean flag = false;
|
||||
for (byte v : value.array()) {
|
||||
if (flag) out.writeArrayMark();
|
||||
@@ -43,11 +43,17 @@ public final class ByteBufferSimpledCoder<R extends Reader, W extends Writer> ex
|
||||
@Override
|
||||
public ByteBuffer convertFrom(R in) {
|
||||
int len = in.readArrayB();
|
||||
int contentLength = -1;
|
||||
if (len == Reader.SIGN_NULL) return null;
|
||||
if (len == Reader.SIGN_NOLENBUTBYTES) {
|
||||
contentLength = in.readMemberContentLength();
|
||||
len = Reader.SIGN_NOLENGTH;
|
||||
}
|
||||
if (len == Reader.SIGN_NOLENGTH) {
|
||||
int size = 0;
|
||||
byte[] data = new byte[8];
|
||||
while (in.hasNext()) {
|
||||
int startPosition = in.position();
|
||||
while (in.hasNext(startPosition, contentLength)) {
|
||||
if (size >= data.length) {
|
||||
byte[] newdata = new byte[data.length + 4];
|
||||
System.arraycopy(data, 0, newdata, 0, size);
|
||||
|
||||
@@ -12,7 +12,9 @@ import org.redkale.convert.Writer;
|
||||
/**
|
||||
* char[] 的SimpledCoder实现
|
||||
*
|
||||
* <p> 详情见: https://redkale.org
|
||||
* <p>
|
||||
* 详情见: https://redkale.org
|
||||
*
|
||||
* @author zhangjx
|
||||
* @param <R> Reader输入的子类型
|
||||
* @param <W> Writer输出的子类型
|
||||
@@ -27,7 +29,7 @@ public final class CharArraySimpledCoder<R extends Reader, W extends Writer> ext
|
||||
out.writeNull();
|
||||
return;
|
||||
}
|
||||
out.writeArrayB(values.length);
|
||||
out.writeArrayB(values.length, CharSimpledCoder.instance, values);
|
||||
boolean flag = false;
|
||||
for (char v : values) {
|
||||
if (flag) out.writeArrayMark();
|
||||
@@ -40,11 +42,17 @@ public final class CharArraySimpledCoder<R extends Reader, W extends Writer> ext
|
||||
@Override
|
||||
public char[] convertFrom(R in) {
|
||||
int len = in.readArrayB();
|
||||
int contentLength = -1;
|
||||
if (len == Reader.SIGN_NULL) return null;
|
||||
if (len == Reader.SIGN_NOLENBUTBYTES) {
|
||||
contentLength = in.readMemberContentLength();
|
||||
len = Reader.SIGN_NOLENGTH;
|
||||
}
|
||||
if (len == Reader.SIGN_NOLENGTH) {
|
||||
int size = 0;
|
||||
char[] data = new char[8];
|
||||
while (in.hasNext()) {
|
||||
int startPosition = in.position();
|
||||
while (in.hasNext(startPosition, contentLength)) {
|
||||
if (size >= data.length) {
|
||||
char[] newdata = new char[data.length + 4];
|
||||
System.arraycopy(data, 0, newdata, 0, size);
|
||||
|
||||
@@ -30,7 +30,7 @@ public final class DoubleArraySimpledCoder<R extends Reader, W extends Writer> e
|
||||
out.writeNull();
|
||||
return;
|
||||
}
|
||||
out.writeArrayB(values.length);
|
||||
out.writeArrayB(values.length, DoubleSimpledCoder.instance, values);
|
||||
boolean flag = false;
|
||||
for (double v : values) {
|
||||
if (flag) out.writeArrayMark();
|
||||
@@ -43,11 +43,17 @@ public final class DoubleArraySimpledCoder<R extends Reader, W extends Writer> e
|
||||
@Override
|
||||
public double[] convertFrom(R in) {
|
||||
int len = in.readArrayB();
|
||||
int contentLength = -1;
|
||||
if (len == Reader.SIGN_NULL) return null;
|
||||
if (len == Reader.SIGN_NOLENBUTBYTES) {
|
||||
contentLength = in.readMemberContentLength();
|
||||
len = Reader.SIGN_NOLENGTH;
|
||||
}
|
||||
if (len == Reader.SIGN_NOLENGTH) {
|
||||
int size = 0;
|
||||
double[] data = new double[8];
|
||||
while (in.hasNext()) {
|
||||
int startPosition = in.position();
|
||||
while (in.hasNext(startPosition, contentLength)) {
|
||||
if (size >= data.length) {
|
||||
double[] newdata = new double[data.length + 4];
|
||||
System.arraycopy(data, 0, newdata, 0, size);
|
||||
|
||||
@@ -12,7 +12,9 @@ import org.redkale.convert.Writer;
|
||||
/**
|
||||
* float[] 的SimpledCoder实现
|
||||
*
|
||||
* <p> 详情见: https://redkale.org
|
||||
* <p>
|
||||
* 详情见: https://redkale.org
|
||||
*
|
||||
* @author zhangjx
|
||||
* @param <R> Reader输入的子类型
|
||||
* @param <W> Writer输出的子类型
|
||||
@@ -27,7 +29,7 @@ public final class FloatArraySimpledCoder<R extends Reader, W extends Writer> ex
|
||||
out.writeNull();
|
||||
return;
|
||||
}
|
||||
out.writeArrayB(values.length);
|
||||
out.writeArrayB(values.length, FloatSimpledCoder.instance, values);
|
||||
boolean flag = false;
|
||||
for (float v : values) {
|
||||
if (flag) out.writeArrayMark();
|
||||
@@ -40,11 +42,17 @@ public final class FloatArraySimpledCoder<R extends Reader, W extends Writer> ex
|
||||
@Override
|
||||
public float[] convertFrom(R in) {
|
||||
int len = in.readArrayB();
|
||||
int contentLength = -1;
|
||||
if (len == Reader.SIGN_NULL) return null;
|
||||
if (len == Reader.SIGN_NOLENBUTBYTES) {
|
||||
contentLength = in.readMemberContentLength();
|
||||
len = Reader.SIGN_NOLENGTH;
|
||||
}
|
||||
if (len == Reader.SIGN_NOLENGTH) {
|
||||
int size = 0;
|
||||
float[] data = new float[8];
|
||||
while (in.hasNext()) {
|
||||
int startPosition = in.position();
|
||||
while (in.hasNext(startPosition, contentLength)) {
|
||||
if (size >= data.length) {
|
||||
float[] newdata = new float[data.length + 4];
|
||||
System.arraycopy(data, 0, newdata, 0, size);
|
||||
|
||||
@@ -30,7 +30,7 @@ public final class IntArraySimpledCoder<R extends Reader, W extends Writer> exte
|
||||
out.writeNull();
|
||||
return;
|
||||
}
|
||||
out.writeArrayB(values.length);
|
||||
out.writeArrayB(values.length, IntSimpledCoder.instance, values);
|
||||
boolean flag = false;
|
||||
for (int v : values) {
|
||||
if (flag) out.writeArrayMark();
|
||||
@@ -43,11 +43,17 @@ public final class IntArraySimpledCoder<R extends Reader, W extends Writer> exte
|
||||
@Override
|
||||
public int[] convertFrom(R in) {
|
||||
int len = in.readArrayB();
|
||||
int contentLength = -1;
|
||||
if (len == Reader.SIGN_NULL) return null;
|
||||
if (len == Reader.SIGN_NOLENBUTBYTES) {
|
||||
contentLength = in.readMemberContentLength();
|
||||
len = Reader.SIGN_NOLENGTH;
|
||||
}
|
||||
if (len == Reader.SIGN_NOLENGTH) {
|
||||
int size = 0;
|
||||
int[] data = new int[8];
|
||||
while (in.hasNext()) {
|
||||
int startPosition = in.position();
|
||||
while (in.hasNext(startPosition, contentLength)) {
|
||||
if (size >= data.length) {
|
||||
int[] newdata = new int[data.length + 4];
|
||||
System.arraycopy(data, 0, newdata, 0, size);
|
||||
|
||||
@@ -30,7 +30,7 @@ public final class LongArraySimpledCoder<R extends Reader, W extends Writer> ext
|
||||
out.writeNull();
|
||||
return;
|
||||
}
|
||||
out.writeArrayB(values.length);
|
||||
out.writeArrayB(values.length, LongSimpledCoder.instance, values);
|
||||
boolean flag = false;
|
||||
for (long v : values) {
|
||||
if (flag) out.writeArrayMark();
|
||||
@@ -43,11 +43,17 @@ public final class LongArraySimpledCoder<R extends Reader, W extends Writer> ext
|
||||
@Override
|
||||
public long[] convertFrom(R in) {
|
||||
int len = in.readArrayB();
|
||||
int contentLength = -1;
|
||||
if (len == Reader.SIGN_NULL) return null;
|
||||
if (len == Reader.SIGN_NOLENBUTBYTES) {
|
||||
contentLength = in.readMemberContentLength();
|
||||
len = Reader.SIGN_NOLENGTH;
|
||||
}
|
||||
if (len == Reader.SIGN_NOLENGTH) {
|
||||
int size = 0;
|
||||
long[] data = new long[8];
|
||||
while (in.hasNext()) {
|
||||
int startPosition = in.position();
|
||||
while (in.hasNext(startPosition, contentLength)) {
|
||||
if (size >= data.length) {
|
||||
long[] newdata = new long[data.length + 4];
|
||||
System.arraycopy(data, 0, newdata, 0, size);
|
||||
|
||||
@@ -12,7 +12,9 @@ import org.redkale.convert.Writer;
|
||||
/**
|
||||
* short[] 的SimpledCoder实现
|
||||
*
|
||||
* <p> 详情见: https://redkale.org
|
||||
* <p>
|
||||
* 详情见: https://redkale.org
|
||||
*
|
||||
* @author zhangjx
|
||||
* @param <R> Reader输入的子类型
|
||||
* @param <W> Writer输出的子类型
|
||||
@@ -27,7 +29,7 @@ public final class ShortArraySimpledCoder<R extends Reader, W extends Writer> ex
|
||||
out.writeNull();
|
||||
return;
|
||||
}
|
||||
out.writeArrayB(values.length);
|
||||
out.writeArrayB(values.length, ShortSimpledCoder.instance, values);
|
||||
boolean flag = false;
|
||||
for (short v : values) {
|
||||
if (flag) out.writeArrayMark();
|
||||
@@ -40,11 +42,17 @@ public final class ShortArraySimpledCoder<R extends Reader, W extends Writer> ex
|
||||
@Override
|
||||
public short[] convertFrom(R in) {
|
||||
int len = in.readArrayB();
|
||||
int contentLength = -1;
|
||||
if (len == Reader.SIGN_NULL) return null;
|
||||
if (len == Reader.SIGN_NOLENBUTBYTES) {
|
||||
contentLength = in.readMemberContentLength();
|
||||
len = Reader.SIGN_NOLENGTH;
|
||||
}
|
||||
if (len == Reader.SIGN_NOLENGTH) {
|
||||
int size = 0;
|
||||
short[] data = new short[8];
|
||||
while (in.hasNext()) {
|
||||
int startPosition = in.position();
|
||||
while (in.hasNext(startPosition, contentLength)) {
|
||||
if (size >= data.length) {
|
||||
short[] newdata = new short[data.length + 4];
|
||||
System.arraycopy(data, 0, newdata, 0, size);
|
||||
|
||||
@@ -12,7 +12,9 @@ import org.redkale.convert.Writer;
|
||||
/**
|
||||
* String[] 的SimpledCoder实现
|
||||
*
|
||||
* <p> 详情见: https://redkale.org
|
||||
* <p>
|
||||
* 详情见: https://redkale.org
|
||||
*
|
||||
* @author zhangjx
|
||||
* @param <R> Reader输入的子类型
|
||||
* @param <W> Writer输出的子类型
|
||||
@@ -27,7 +29,7 @@ public final class StringArraySimpledCoder<R extends Reader, W extends Writer> e
|
||||
out.writeNull();
|
||||
return;
|
||||
}
|
||||
out.writeArrayB(values.length);
|
||||
out.writeArrayB(values.length, StringSimpledCoder.instance, values);
|
||||
boolean flag = false;
|
||||
for (String v : values) {
|
||||
if (flag) out.writeArrayMark();
|
||||
@@ -40,11 +42,17 @@ public final class StringArraySimpledCoder<R extends Reader, W extends Writer> e
|
||||
@Override
|
||||
public String[] convertFrom(R in) {
|
||||
int len = in.readArrayB();
|
||||
int contentLength = -1;
|
||||
if (len == Reader.SIGN_NULL) return null;
|
||||
if (len == Reader.SIGN_NOLENBUTBYTES) {
|
||||
contentLength = in.readMemberContentLength();
|
||||
len = Reader.SIGN_NOLENGTH;
|
||||
}
|
||||
if (len == Reader.SIGN_NOLENGTH) {
|
||||
int size = 0;
|
||||
String[] data = new String[8];
|
||||
while (in.hasNext()) {
|
||||
int startPosition = in.position();
|
||||
while (in.hasNext(startPosition, contentLength)) {
|
||||
if (size >= data.length) {
|
||||
String[] newdata = new String[data.length + 4];
|
||||
System.arraycopy(data, 0, newdata, 0, size);
|
||||
|
||||
@@ -156,10 +156,13 @@ public class JsonByteBufferReader extends JsonReader {
|
||||
/**
|
||||
* 判断对象是否存在下一个属性或者数组是否存在下一个元素
|
||||
*
|
||||
* @param startPosition 起始位置
|
||||
* @param contentLength 内容大小, 不确定的传-1
|
||||
*
|
||||
* @return 是否存在
|
||||
*/
|
||||
@Override
|
||||
public final boolean hasNext() {
|
||||
public boolean hasNext(int startPosition, int contentLength) {
|
||||
char ch = nextGoodChar();
|
||||
if (ch == ',') return true;
|
||||
if (ch == '}' || ch == ']' || ch == 0) return false;
|
||||
|
||||
@@ -244,13 +244,26 @@ public class JsonReader extends Reader {
|
||||
throw new ConvertException("'" + new String(text) + "'expected a ':' but '" + ch + "'(position = " + position + ") in (" + new String(this.text) + ")");
|
||||
}
|
||||
|
||||
@Override
|
||||
public int position() {
|
||||
return this.position;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int readMemberContentLength() {
|
||||
return -1;
|
||||
}
|
||||
|
||||
/**
|
||||
* 判断对象是否存在下一个属性或者数组是否存在下一个元素
|
||||
*
|
||||
* @param startPosition 起始位置
|
||||
* @param contentLength 内容大小, 不确定的传-1
|
||||
*
|
||||
* @return 是否存在
|
||||
*/
|
||||
@Override
|
||||
public boolean hasNext() {
|
||||
public boolean hasNext(int startPosition, int contentLength) {
|
||||
char ch = this.text[++this.position];
|
||||
if (ch == ',') return true;
|
||||
if (ch == '}' || ch == ']') return false;
|
||||
@@ -456,11 +469,17 @@ public class JsonReader extends Reader {
|
||||
@Override
|
||||
public final byte[] readByteArray() {
|
||||
int len = readArrayB();
|
||||
int contentLength = -1;
|
||||
if (len == Reader.SIGN_NULL) return null;
|
||||
if (len == Reader.SIGN_NOLENBUTBYTES) {
|
||||
contentLength = readMemberContentLength();
|
||||
len = Reader.SIGN_NOLENGTH;
|
||||
}
|
||||
if (len == Reader.SIGN_NOLENGTH) {
|
||||
int size = 0;
|
||||
byte[] data = new byte[8];
|
||||
while (hasNext()) {
|
||||
int startPosition = position();
|
||||
while (hasNext(startPosition, contentLength)) {
|
||||
if (size >= data.length) {
|
||||
byte[] newdata = new byte[data.length + 4];
|
||||
System.arraycopy(data, 0, newdata, 0, size);
|
||||
|
||||
@@ -194,7 +194,7 @@ public class JsonWriter extends Writer {
|
||||
writeNull();
|
||||
return;
|
||||
}
|
||||
writeArrayB(values.length);
|
||||
writeArrayB(values.length, null, values);
|
||||
boolean flag = false;
|
||||
for (byte v : values) {
|
||||
if (flag) writeArrayMark();
|
||||
@@ -345,7 +345,7 @@ public class JsonWriter extends Writer {
|
||||
}
|
||||
|
||||
@Override
|
||||
public final void writeArrayB(int size) {
|
||||
public final void writeArrayB(int size, Encodeable<Writer, Object> encoder, Object obj) {
|
||||
writeTo('[');
|
||||
}
|
||||
|
||||
@@ -360,7 +360,7 @@ public class JsonWriter extends Writer {
|
||||
}
|
||||
|
||||
@Override
|
||||
public final void writeMapB(int size) {
|
||||
public final void writeMapB(int size, Encodeable<Writer, Object> keyEncoder, Encodeable<Writer, Object> valueEncoder, Object obj) {
|
||||
writeTo('{');
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user