T - the type of the object deserializedpublic interface SizedReader<T> extends Marshallable
SizedWriter, i. e. assuming the length
of the serialized form isn't written in the beginning of the serialized form itself, but managed
by ChronicleHash implementation and passed to the reading methods.
Implementation example:
class LongPair { long first, second; }
enum LongPairArrayReader
implements SizedReader<LongPair[]>, EnumMarshallable<LongPairArrayReader> {
INSTANCE;
@Override
@NotNull
public LongPair[] read(@NotNull Bytes in, long size,
@Nullable LongPair[] using) {
if (size > Integer.MAX_VALUE * 16L)
throw new IllegalStateException("LongPair[] size couldn't be " + (size / 16L));
int resLen = (int) (size / 16L);
LongPair[] res;
if (using != null) {
if (using.length == resLen) {
res = using;
} else {
res = Arrays.copyOf(using, resLen);
}
} else {
res = new LongPair[resLen];
}
for (int i = 0; i < resLen; i++) {
LongPair pair = res[i];
if (pair == null)
res[i] = pair = new LongPair();
pair.first = in.readLong();
pair.second = in.readLong();
}
return res;
}
@Override
public LongPairArrayReader readResolve() {
return INSTANCE;
}
}SizedWriterEMPTYDISCARD| Modifier and Type | Method and Description |
|---|---|
T |
read(Bytes in,
long size,
T using)
Reads and returns the object from
RandomCommon.readPosition() (i. |
writeMarshallable, writeValuereadMarshallable@NotNull T read(Bytes in, long size, @Nullable T using)
RandomCommon.readPosition() (i. e. the current position)
to Bytes.readPosition() + size in the given in. Should attempt to reuse the
given using object, i. e. to read the deserialized data into the given object. If it
is possible, this objects then returned from this method. If it is impossible for any reason,
a new object should be created and returned. The given using object could be null, in this case this method, of cause, should create a new object.
This method should increment the position in the given Bytes by the given size.
in - the Bytes to read the object fromsize - the size of the serialized form of the returned objectusing - the object to read the deserialized data into, could be nullCopyright © 2016. All rights reserved.