protobuf
This commit is contained in:
@@ -7,7 +7,8 @@ package org.redkale.convert;
|
|||||||
|
|
||||||
import java.lang.reflect.*;
|
import java.lang.reflect.*;
|
||||||
import java.util.*;
|
import java.util.*;
|
||||||
import java.util.concurrent.locks.*;
|
import java.util.concurrent.locks.Condition;
|
||||||
|
import java.util.concurrent.locks.ReentrantLock;
|
||||||
import org.redkale.annotation.Nullable;
|
import org.redkale.annotation.Nullable;
|
||||||
import org.redkale.convert.ext.StringSimpledCoder;
|
import org.redkale.convert.ext.StringSimpledCoder;
|
||||||
import org.redkale.util.*;
|
import org.redkale.util.*;
|
||||||
@@ -385,6 +386,7 @@ public class ObjectDecoder<R extends Reader, T> implements Decodeable<R, T> {
|
|||||||
first = false;
|
first = false;
|
||||||
}
|
}
|
||||||
objin.readObjectE(typeClass);
|
objin.readObjectE(typeClass);
|
||||||
|
offerReader(in, objin);
|
||||||
return result;
|
return result;
|
||||||
} else { // 带参数的构造函数
|
} else { // 带参数的构造函数
|
||||||
final DeMember<R, T, ?>[] constructorFields = this.creatorConstructorMembers;
|
final DeMember<R, T, ?>[] constructorFields = this.creatorConstructorMembers;
|
||||||
@@ -414,6 +416,7 @@ public class ObjectDecoder<R extends Reader, T> implements Decodeable<R, T> {
|
|||||||
first = false;
|
first = false;
|
||||||
}
|
}
|
||||||
objin.readObjectE(typeClass);
|
objin.readObjectE(typeClass);
|
||||||
|
offerReader(in, objin);
|
||||||
if (this.creator == null) {
|
if (this.creator == null) {
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
@@ -442,6 +445,10 @@ public class ObjectDecoder<R extends Reader, T> implements Decodeable<R, T> {
|
|||||||
return in;
|
return in;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
protected void offerReader(R parent, R out) {
|
||||||
|
// do nothing
|
||||||
|
}
|
||||||
|
|
||||||
protected Object readDeMemberValue(R in, DeMember member, boolean first) {
|
protected Object readDeMemberValue(R in, DeMember member, boolean first) {
|
||||||
return member.read(in);
|
return member.read(in);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -4,16 +4,17 @@
|
|||||||
*/
|
*/
|
||||||
package org.redkale.convert.pb;
|
package org.redkale.convert.pb;
|
||||||
|
|
||||||
import java.util.concurrent.atomic.AtomicInteger;
|
import java.util.Collection;
|
||||||
import java.util.concurrent.atomic.AtomicLong;
|
import java.util.concurrent.atomic.*;
|
||||||
import org.redkale.convert.SimpledCoder;
|
import org.redkale.convert.SimpledCoder;
|
||||||
import org.redkale.util.Utility;
|
import org.redkale.util.*;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
*
|
*
|
||||||
* @author zhangjx
|
* @author zhangjx
|
||||||
*/
|
*/
|
||||||
public class ProtobufCoders {
|
public abstract class ProtobufCoders {
|
||||||
|
|
||||||
private ProtobufCoders() {
|
private ProtobufCoders() {
|
||||||
// do nothing
|
// do nothing
|
||||||
}
|
}
|
||||||
@@ -306,4 +307,165 @@ public class ProtobufCoders {
|
|||||||
return in.readAtomicLongs();
|
return in.readAtomicLongs();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public static class ProtobufBoolCollectionSimpledCoder
|
||||||
|
extends SimpledCoder<ProtobufReader, ProtobufWriter, Collection<Boolean>> implements ProtobufPrimitivable {
|
||||||
|
|
||||||
|
private final Creator<? extends Collection> creator;
|
||||||
|
|
||||||
|
public ProtobufBoolCollectionSimpledCoder(Creator<? extends Collection> creator) {
|
||||||
|
this.creator = creator;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void convertTo(ProtobufWriter out, Collection<Boolean> values) {
|
||||||
|
out.writeBools(values);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public Collection<Boolean> convertFrom(ProtobufReader in) {
|
||||||
|
return in.readBools(creator);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public static class ProtobufByteCollectionSimpledCoder
|
||||||
|
extends SimpledCoder<ProtobufReader, ProtobufWriter, Collection<Byte>> implements ProtobufPrimitivable {
|
||||||
|
|
||||||
|
private final Creator<? extends Collection> creator;
|
||||||
|
|
||||||
|
public ProtobufByteCollectionSimpledCoder(Creator<? extends Collection> creator) {
|
||||||
|
this.creator = creator;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void convertTo(ProtobufWriter out, Collection<Byte> values) {
|
||||||
|
out.writeBytes(values);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public Collection<Byte> convertFrom(ProtobufReader in) {
|
||||||
|
return in.readBytes(creator);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public static class ProtobufCharCollectionSimpledCoder
|
||||||
|
extends SimpledCoder<ProtobufReader, ProtobufWriter, Collection<Character>>
|
||||||
|
implements ProtobufPrimitivable {
|
||||||
|
|
||||||
|
private final Creator<? extends Collection> creator;
|
||||||
|
|
||||||
|
public ProtobufCharCollectionSimpledCoder(Creator<? extends Collection> creator) {
|
||||||
|
this.creator = creator;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void convertTo(ProtobufWriter out, Collection<Character> values) {
|
||||||
|
out.writeChars(values);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public Collection<Character> convertFrom(ProtobufReader in) {
|
||||||
|
return in.readChars(creator);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public static class ProtobufShortCollectionSimpledCoder
|
||||||
|
extends SimpledCoder<ProtobufReader, ProtobufWriter, Collection<Short>> implements ProtobufPrimitivable {
|
||||||
|
|
||||||
|
private final Creator<? extends Collection> creator;
|
||||||
|
|
||||||
|
public ProtobufShortCollectionSimpledCoder(Creator<? extends Collection> creator) {
|
||||||
|
this.creator = creator;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void convertTo(ProtobufWriter out, Collection<Short> values) {
|
||||||
|
out.writeShorts(values);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public Collection<Short> convertFrom(ProtobufReader in) {
|
||||||
|
return in.readShorts(creator);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public static class ProtobufIntCollectionSimpledCoder
|
||||||
|
extends SimpledCoder<ProtobufReader, ProtobufWriter, Collection<Integer>> implements ProtobufPrimitivable {
|
||||||
|
|
||||||
|
private final Creator<? extends Collection> creator;
|
||||||
|
|
||||||
|
public ProtobufIntCollectionSimpledCoder(Creator<? extends Collection> creator) {
|
||||||
|
this.creator = creator;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void convertTo(ProtobufWriter out, Collection<Integer> values) {
|
||||||
|
out.writeInts(values);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public Collection<Integer> convertFrom(ProtobufReader in) {
|
||||||
|
return in.readInts(creator);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public static class ProtobufFloatCollectionSimpledCoder
|
||||||
|
extends SimpledCoder<ProtobufReader, ProtobufWriter, Collection<Float>> implements ProtobufPrimitivable {
|
||||||
|
|
||||||
|
private final Creator<? extends Collection> creator;
|
||||||
|
|
||||||
|
public ProtobufFloatCollectionSimpledCoder(Creator<? extends Collection> creator) {
|
||||||
|
this.creator = creator;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void convertTo(ProtobufWriter out, Collection<Float> values) {
|
||||||
|
out.writeFloats(values);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public Collection<Float> convertFrom(ProtobufReader in) {
|
||||||
|
return in.readFloats(creator);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public static class ProtobufLongCollectionSimpledCoder
|
||||||
|
extends SimpledCoder<ProtobufReader, ProtobufWriter, Collection<Long>> implements ProtobufPrimitivable {
|
||||||
|
|
||||||
|
private final Creator<? extends Collection> creator;
|
||||||
|
|
||||||
|
public ProtobufLongCollectionSimpledCoder(Creator<? extends Collection> creator) {
|
||||||
|
this.creator = creator;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void convertTo(ProtobufWriter out, Collection<Long> values) {
|
||||||
|
out.writeLongs(values);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public Collection<Long> convertFrom(ProtobufReader in) {
|
||||||
|
return in.readLongs(creator);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public static class ProtobufDoubleCollectionSimpledCoder
|
||||||
|
extends SimpledCoder<ProtobufReader, ProtobufWriter, Collection<Double>> implements ProtobufPrimitivable {
|
||||||
|
|
||||||
|
private final Creator<? extends Collection> creator;
|
||||||
|
|
||||||
|
public ProtobufDoubleCollectionSimpledCoder(Creator<? extends Collection> creator) {
|
||||||
|
this.creator = creator;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void convertTo(ProtobufWriter out, Collection<Double> values) {
|
||||||
|
out.writeDoubles(values);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public Collection<Double> convertFrom(ProtobufReader in) {
|
||||||
|
return in.readDoubles(creator);
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -11,8 +11,32 @@ import java.util.*;
|
|||||||
import java.util.concurrent.atomic.*;
|
import java.util.concurrent.atomic.*;
|
||||||
import java.util.stream.Stream;
|
import java.util.stream.Stream;
|
||||||
import org.redkale.convert.*;
|
import org.redkale.convert.*;
|
||||||
import org.redkale.util.AnyValue;
|
import org.redkale.convert.pb.ProtobufCoders.ProtobufAtomicIntegerArraySimpledCoder;
|
||||||
import org.redkale.util.AnyValueWriter;
|
import org.redkale.convert.pb.ProtobufCoders.ProtobufAtomicLongArraySimpledCoder;
|
||||||
|
import org.redkale.convert.pb.ProtobufCoders.ProtobufBoolArraySimpledCoder2;
|
||||||
|
import org.redkale.convert.pb.ProtobufCoders.ProtobufBoolCollectionSimpledCoder;
|
||||||
|
import org.redkale.convert.pb.ProtobufCoders.ProtobufByteArraySimpledCoder;
|
||||||
|
import org.redkale.convert.pb.ProtobufCoders.ProtobufByteArraySimpledCoder2;
|
||||||
|
import org.redkale.convert.pb.ProtobufCoders.ProtobufByteCollectionSimpledCoder;
|
||||||
|
import org.redkale.convert.pb.ProtobufCoders.ProtobufCharArraySimpledCoder;
|
||||||
|
import org.redkale.convert.pb.ProtobufCoders.ProtobufCharArraySimpledCoder2;
|
||||||
|
import org.redkale.convert.pb.ProtobufCoders.ProtobufCharCollectionSimpledCoder;
|
||||||
|
import org.redkale.convert.pb.ProtobufCoders.ProtobufDoubleArraySimpledCoder;
|
||||||
|
import org.redkale.convert.pb.ProtobufCoders.ProtobufDoubleArraySimpledCoder2;
|
||||||
|
import org.redkale.convert.pb.ProtobufCoders.ProtobufDoubleCollectionSimpledCoder;
|
||||||
|
import org.redkale.convert.pb.ProtobufCoders.ProtobufFloatArraySimpledCoder;
|
||||||
|
import org.redkale.convert.pb.ProtobufCoders.ProtobufFloatArraySimpledCoder2;
|
||||||
|
import org.redkale.convert.pb.ProtobufCoders.ProtobufFloatCollectionSimpledCoder;
|
||||||
|
import org.redkale.convert.pb.ProtobufCoders.ProtobufIntArraySimpledCoder;
|
||||||
|
import org.redkale.convert.pb.ProtobufCoders.ProtobufIntArraySimpledCoder2;
|
||||||
|
import org.redkale.convert.pb.ProtobufCoders.ProtobufIntCollectionSimpledCoder;
|
||||||
|
import org.redkale.convert.pb.ProtobufCoders.ProtobufLongArraySimpledCoder;
|
||||||
|
import org.redkale.convert.pb.ProtobufCoders.ProtobufLongArraySimpledCoder2;
|
||||||
|
import org.redkale.convert.pb.ProtobufCoders.ProtobufLongCollectionSimpledCoder;
|
||||||
|
import org.redkale.convert.pb.ProtobufCoders.ProtobufShortArraySimpledCoder;
|
||||||
|
import org.redkale.convert.pb.ProtobufCoders.ProtobufShortArraySimpledCoder2;
|
||||||
|
import org.redkale.convert.pb.ProtobufCoders.ProtobufShortCollectionSimpledCoder;
|
||||||
|
import org.redkale.util.*;
|
||||||
|
|
||||||
/** @author zhangjx */
|
/** @author zhangjx */
|
||||||
public class ProtobufFactory extends ConvertFactory<ProtobufReader, ProtobufWriter> {
|
public class ProtobufFactory extends ConvertFactory<ProtobufReader, ProtobufWriter> {
|
||||||
@@ -42,23 +66,23 @@ public class ProtobufFactory extends ConvertFactory<ProtobufReader, ProtobufWrit
|
|||||||
instance.register(AnyValue.class, instance.loadDecoder(AnyValueWriter.class));
|
instance.register(AnyValue.class, instance.loadDecoder(AnyValueWriter.class));
|
||||||
instance.register(AnyValue.class, instance.loadEncoder(AnyValueWriter.class));
|
instance.register(AnyValue.class, instance.loadEncoder(AnyValueWriter.class));
|
||||||
instance.register(boolean[].class, ProtobufCoders.ProtobufBoolArraySimpledCoder.instance);
|
instance.register(boolean[].class, ProtobufCoders.ProtobufBoolArraySimpledCoder.instance);
|
||||||
instance.register(byte[].class, ProtobufCoders.ProtobufByteArraySimpledCoder.instance);
|
instance.register(byte[].class, ProtobufByteArraySimpledCoder.instance);
|
||||||
instance.register(char[].class, ProtobufCoders.ProtobufCharArraySimpledCoder.instance);
|
instance.register(char[].class, ProtobufCharArraySimpledCoder.instance);
|
||||||
instance.register(short[].class, ProtobufCoders.ProtobufShortArraySimpledCoder.instance);
|
instance.register(short[].class, ProtobufShortArraySimpledCoder.instance);
|
||||||
instance.register(int[].class, ProtobufCoders.ProtobufIntArraySimpledCoder.instance);
|
instance.register(int[].class, ProtobufIntArraySimpledCoder.instance);
|
||||||
instance.register(float[].class, ProtobufCoders.ProtobufFloatArraySimpledCoder.instance);
|
instance.register(float[].class, ProtobufFloatArraySimpledCoder.instance);
|
||||||
instance.register(long[].class, ProtobufCoders.ProtobufLongArraySimpledCoder.instance);
|
instance.register(long[].class, ProtobufLongArraySimpledCoder.instance);
|
||||||
instance.register(double[].class, ProtobufCoders.ProtobufDoubleArraySimpledCoder.instance);
|
instance.register(double[].class, ProtobufDoubleArraySimpledCoder.instance);
|
||||||
instance.register(Boolean[].class, ProtobufCoders.ProtobufBoolArraySimpledCoder2.instance);
|
instance.register(Boolean[].class, ProtobufBoolArraySimpledCoder2.instance);
|
||||||
instance.register(Byte[].class, ProtobufCoders.ProtobufByteArraySimpledCoder2.instance);
|
instance.register(Byte[].class, ProtobufByteArraySimpledCoder2.instance);
|
||||||
instance.register(Character[].class, ProtobufCoders.ProtobufCharArraySimpledCoder2.instance);
|
instance.register(Character[].class, ProtobufCharArraySimpledCoder2.instance);
|
||||||
instance.register(Short[].class, ProtobufCoders.ProtobufShortArraySimpledCoder2.instance);
|
instance.register(Short[].class, ProtobufShortArraySimpledCoder2.instance);
|
||||||
instance.register(Integer[].class, ProtobufCoders.ProtobufIntArraySimpledCoder2.instance);
|
instance.register(Integer[].class, ProtobufIntArraySimpledCoder2.instance);
|
||||||
instance.register(Float[].class, ProtobufCoders.ProtobufFloatArraySimpledCoder2.instance);
|
instance.register(Float[].class, ProtobufFloatArraySimpledCoder2.instance);
|
||||||
instance.register(Long[].class, ProtobufCoders.ProtobufLongArraySimpledCoder2.instance);
|
instance.register(Long[].class, ProtobufLongArraySimpledCoder2.instance);
|
||||||
instance.register(Double[].class, ProtobufCoders.ProtobufDoubleArraySimpledCoder2.instance);
|
instance.register(Double[].class, ProtobufDoubleArraySimpledCoder2.instance);
|
||||||
instance.register(AtomicInteger[].class, ProtobufCoders.ProtobufAtomicIntegerArraySimpledCoder.instance);
|
instance.register(AtomicInteger[].class, ProtobufAtomicIntegerArraySimpledCoder.instance);
|
||||||
instance.register(AtomicLong[].class, ProtobufCoders.ProtobufAtomicLongArraySimpledCoder.instance);
|
instance.register(AtomicLong[].class, ProtobufAtomicLongArraySimpledCoder.instance);
|
||||||
}
|
}
|
||||||
|
|
||||||
@SuppressWarnings("OverridableMethodCallInConstructor")
|
@SuppressWarnings("OverridableMethodCallInConstructor")
|
||||||
@@ -151,6 +175,35 @@ public class ProtobufFactory extends ConvertFactory<ProtobufReader, ProtobufWrit
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
protected <E> Decodeable<ProtobufReader, E> createCollectionDecoder(Type type) {
|
protected <E> Decodeable<ProtobufReader, E> createCollectionDecoder(Type type) {
|
||||||
|
if (type instanceof ParameterizedType) {
|
||||||
|
ParameterizedType pt = (ParameterizedType) type;
|
||||||
|
Type componentType = pt.getActualTypeArguments()[0];
|
||||||
|
if (componentType == Boolean.class) {
|
||||||
|
Creator<? extends Collection> creator = loadCreator((Class) pt.getRawType());
|
||||||
|
return (Decodeable) new ProtobufBoolCollectionSimpledCoder(creator);
|
||||||
|
} else if (componentType == Byte.class) {
|
||||||
|
Creator<? extends Collection> creator = loadCreator((Class) pt.getRawType());
|
||||||
|
return (Decodeable) new ProtobufByteCollectionSimpledCoder(creator);
|
||||||
|
} else if (componentType == Character.class) {
|
||||||
|
Creator<? extends Collection> creator = loadCreator((Class) pt.getRawType());
|
||||||
|
return (Decodeable) new ProtobufCharCollectionSimpledCoder(creator);
|
||||||
|
} else if (componentType == Short.class) {
|
||||||
|
Creator<? extends Collection> creator = loadCreator((Class) pt.getRawType());
|
||||||
|
return (Decodeable) new ProtobufShortCollectionSimpledCoder(creator);
|
||||||
|
} else if (componentType == Integer.class) {
|
||||||
|
Creator<? extends Collection> creator = loadCreator((Class) pt.getRawType());
|
||||||
|
return (Decodeable) new ProtobufIntCollectionSimpledCoder(creator);
|
||||||
|
} else if (componentType == Float.class) {
|
||||||
|
Creator<? extends Collection> creator = loadCreator((Class) pt.getRawType());
|
||||||
|
return (Decodeable) new ProtobufFloatCollectionSimpledCoder(creator);
|
||||||
|
} else if (componentType == Long.class) {
|
||||||
|
Creator<? extends Collection> creator = loadCreator((Class) pt.getRawType());
|
||||||
|
return (Decodeable) new ProtobufLongCollectionSimpledCoder(creator);
|
||||||
|
} else if (componentType == Double.class) {
|
||||||
|
Creator<? extends Collection> creator = loadCreator((Class) pt.getRawType());
|
||||||
|
return (Decodeable) new ProtobufDoubleCollectionSimpledCoder(creator);
|
||||||
|
}
|
||||||
|
}
|
||||||
return new ProtobufCollectionDecoder(this, type);
|
return new ProtobufCollectionDecoder(this, type);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -11,6 +11,7 @@ import java.util.*;
|
|||||||
import java.util.concurrent.atomic.AtomicInteger;
|
import java.util.concurrent.atomic.AtomicInteger;
|
||||||
import java.util.concurrent.atomic.AtomicLong;
|
import java.util.concurrent.atomic.AtomicLong;
|
||||||
import org.redkale.convert.*;
|
import org.redkale.convert.*;
|
||||||
|
import org.redkale.util.Creator;
|
||||||
|
|
||||||
/** @author zhangjx */
|
/** @author zhangjx */
|
||||||
public class ProtobufReader extends Reader {
|
public class ProtobufReader extends Reader {
|
||||||
@@ -224,6 +225,15 @@ public class ProtobufReader extends Reader {
|
|||||||
return data;
|
return data;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public Collection<Boolean> readBools(Creator<? extends Collection> creator) {
|
||||||
|
int size = readRawVarint32();
|
||||||
|
Collection<Boolean> data = creator.create();
|
||||||
|
for (int i = 0; i < size; i++) {
|
||||||
|
data.add(readBoolean());
|
||||||
|
}
|
||||||
|
return data;
|
||||||
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public final byte readByte() {
|
public final byte readByte() {
|
||||||
return (byte) readInt();
|
return (byte) readInt();
|
||||||
@@ -233,6 +243,14 @@ public class ProtobufReader extends Reader {
|
|||||||
return readByteArray();
|
return readByteArray();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public Collection<Byte> readBytes(Creator<? extends Collection> creator) {
|
||||||
|
Collection<Byte> data = creator.create();
|
||||||
|
for (byte b : readByteArray()) {
|
||||||
|
data.add(b);
|
||||||
|
}
|
||||||
|
return data;
|
||||||
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public final char readChar() {
|
public final char readChar() {
|
||||||
return (char) readInt();
|
return (char) readInt();
|
||||||
@@ -253,6 +271,17 @@ public class ProtobufReader extends Reader {
|
|||||||
return rs;
|
return rs;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public Collection<Character> readChars(Creator<? extends Collection> creator) {
|
||||||
|
Collection<Character> data = creator.create();
|
||||||
|
int len = readRawVarint32();
|
||||||
|
while (len > 0) {
|
||||||
|
char val = readChar();
|
||||||
|
data.add(val);
|
||||||
|
len -= ProtobufFactory.computeSInt32SizeNoTag(val);
|
||||||
|
}
|
||||||
|
return data;
|
||||||
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public final short readShort() {
|
public final short readShort() {
|
||||||
return (short) readInt();
|
return (short) readInt();
|
||||||
@@ -273,6 +302,17 @@ public class ProtobufReader extends Reader {
|
|||||||
return rs;
|
return rs;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public Collection<Short> readShorts(Creator<? extends Collection> creator) {
|
||||||
|
Collection<Short> data = creator.create();
|
||||||
|
int len = readRawVarint32();
|
||||||
|
while (len > 0) {
|
||||||
|
short val = readShort();
|
||||||
|
data.add(val);
|
||||||
|
len -= ProtobufFactory.computeSInt32SizeNoTag(val);
|
||||||
|
}
|
||||||
|
return data;
|
||||||
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public final int readInt() { // readSInt32
|
public final int readInt() { // readSInt32
|
||||||
int n = readRawVarint32();
|
int n = readRawVarint32();
|
||||||
@@ -294,6 +334,17 @@ public class ProtobufReader extends Reader {
|
|||||||
return rs;
|
return rs;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public Collection<Integer> readInts(Creator<? extends Collection> creator) {
|
||||||
|
Collection<Integer> data = creator.create();
|
||||||
|
int len = readRawVarint32();
|
||||||
|
while (len > 0) {
|
||||||
|
int val = readInt();
|
||||||
|
data.add(val);
|
||||||
|
len -= ProtobufFactory.computeSInt32SizeNoTag(val);
|
||||||
|
}
|
||||||
|
return data;
|
||||||
|
}
|
||||||
|
|
||||||
public AtomicInteger[] readAtomicIntegers() {
|
public AtomicInteger[] readAtomicIntegers() {
|
||||||
int len = readRawVarint32();
|
int len = readRawVarint32();
|
||||||
List<AtomicInteger> list = new ArrayList<>(len);
|
List<AtomicInteger> list = new ArrayList<>(len);
|
||||||
@@ -305,6 +356,17 @@ public class ProtobufReader extends Reader {
|
|||||||
return list.toArray(new AtomicInteger[list.size()]);
|
return list.toArray(new AtomicInteger[list.size()]);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public Collection<AtomicInteger> readAtomicIntegers(Creator<? extends Collection> creator) {
|
||||||
|
Collection<AtomicInteger> data = creator.create();
|
||||||
|
int len = readRawVarint32();
|
||||||
|
while (len > 0) {
|
||||||
|
int val = readInt();
|
||||||
|
data.add(new AtomicInteger(val));
|
||||||
|
len -= ProtobufFactory.computeSInt32SizeNoTag(val);
|
||||||
|
}
|
||||||
|
return data;
|
||||||
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public final float readFloat() {
|
public final float readFloat() {
|
||||||
return Float.intBitsToFloat(readRawLittleEndian32());
|
return Float.intBitsToFloat(readRawLittleEndian32());
|
||||||
@@ -319,6 +381,15 @@ public class ProtobufReader extends Reader {
|
|||||||
return rs;
|
return rs;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public Collection<Float> readFloats(Creator<? extends Collection> creator) {
|
||||||
|
Collection<Float> data = creator.create();
|
||||||
|
int len = readRawVarint32() / 4;
|
||||||
|
for (int i = 0; i < len; i++) {
|
||||||
|
data.add(readFloat());
|
||||||
|
}
|
||||||
|
return data;
|
||||||
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public final long readLong() { // readSInt64
|
public final long readLong() { // readSInt64
|
||||||
long n = readRawVarint64();
|
long n = readRawVarint64();
|
||||||
@@ -340,6 +411,17 @@ public class ProtobufReader extends Reader {
|
|||||||
return rs;
|
return rs;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public Collection<Long> readLongs(Creator<? extends Collection> creator) {
|
||||||
|
Collection<Long> data = creator.create();
|
||||||
|
int len = readRawVarint32();
|
||||||
|
while (len > 0) {
|
||||||
|
long val = readLong();
|
||||||
|
data.add(val);
|
||||||
|
len -= ProtobufFactory.computeSInt64SizeNoTag(val);
|
||||||
|
}
|
||||||
|
return data;
|
||||||
|
}
|
||||||
|
|
||||||
public AtomicLong[] readAtomicLongs() {
|
public AtomicLong[] readAtomicLongs() {
|
||||||
int len = readRawVarint32();
|
int len = readRawVarint32();
|
||||||
List<AtomicLong> list = new ArrayList<>(len);
|
List<AtomicLong> list = new ArrayList<>(len);
|
||||||
@@ -351,6 +433,17 @@ public class ProtobufReader extends Reader {
|
|||||||
return list.toArray(new AtomicLong[list.size()]);
|
return list.toArray(new AtomicLong[list.size()]);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public Collection<AtomicLong> readAtomicLongs(Creator<? extends Collection> creator) {
|
||||||
|
Collection<AtomicLong> data = creator.create();
|
||||||
|
int len = readRawVarint32();
|
||||||
|
while (len > 0) {
|
||||||
|
long val = readLong();
|
||||||
|
data.add(new AtomicLong(val));
|
||||||
|
len -= ProtobufFactory.computeSInt64SizeNoTag(val);
|
||||||
|
}
|
||||||
|
return data;
|
||||||
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public final double readDouble() {
|
public final double readDouble() {
|
||||||
return Double.longBitsToDouble(readRawLittleEndian64());
|
return Double.longBitsToDouble(readRawLittleEndian64());
|
||||||
@@ -365,6 +458,15 @@ public class ProtobufReader extends Reader {
|
|||||||
return rs;
|
return rs;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public Collection<Double> readDoubles(Creator<? extends Collection> creator) {
|
||||||
|
Collection<Double> data = creator.create();
|
||||||
|
int len = readRawVarint32() / 8;
|
||||||
|
for (int i = 0; i < len; i++) {
|
||||||
|
data.add(readDouble());
|
||||||
|
}
|
||||||
|
return data;
|
||||||
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public final String readClassName() {
|
public final String readClassName() {
|
||||||
return "";
|
return "";
|
||||||
|
|||||||
Reference in New Issue
Block a user