T - the type of the object marshalledpublic interface SizedWriter<T> extends Marshallable
ChronicleHash into SizedReader.read(net.openhft.chronicle.bytes.Bytes, long, T) deserialization method.
Implementation example:
class LongPair { long first, second; }
enum LongPairArrayWriter
implements SizedWriter<LongPair[]>, EnumMarshallable<LongPairArrayWriter> {
INSTANCE;
@Override
public long size(@NotNull LongPair[] toWrite) {
return toWrite.length * 16L;
}
@Override
public void write(@NotNull Bytes out, long size,
@NotNull LongPair[] toWrite) {
for (LongPair pair : toWrite) {
out.writeLong(pair.first);
out.writeLong(pair.second);
}
}
@Override
public LongPairArrayWriter readResolve() {
return INSTANCE;
}
}SizedReaderEMPTYDISCARD| Modifier and Type | Method and Description |
|---|---|
long |
size(T toWrite)
Returns the length (in bytes) of the serialized form of the given object.
|
void |
write(Bytes out,
long size,
T toWrite)
Serializes the given object to the given
out, without writing the length of the
serialized form itself. |
writeMarshallable, writeValuereadMarshallablelong size(@NotNull
T toWrite)
out on
write(out, size, toWrite) call.toWrite - the object which serialized form length should be returnedvoid write(Bytes out, long size, @NotNull T toWrite)
out, without writing the length of the
serialized form itself.
Implementation of this method should increment the position of the given out by size(toWrite). The given object
should be written into these range between the initial bytes' position and the
position after this method call returns.
out - the Bytes to write the given object tosize - the size, returned by size(Object) for the given toWrite object.
it is given, because size might be needed during serialization, and it's computation has
non-constant complexity, i. e. if serializing a CharSequence using variable-length
encoding like UTF-8.toWrite - the object to serializeSizedReader.read(Bytes, long, Object)Copyright © 2016. All rights reserved.