E
- the type of the object marshalledpublic interface BytesWriter<E> extends Serializable
Bytes
writer) which 1) knows the length of serialized form
of any object before actual serialization 2) doesn't include that length in the serialized
form itself, assuming it will be passed by the ChronicleHash
into
BytesReader.read(Bytes, long)
deserialization method.
Implementation example:
class LongPair { long first, second; }
enum LongPairArrayWriter implements BytesWriter<LongPair[]> {
INSTANCE;
@Override
public long size(LongPair[] longPairs) {
return longPairs.length * 16L;
}
@Override
public void write(Bytes bytes, LongPair[] longPairs) {
for (LongPair pair : longPairs) {
bytes.writeLong(pair.first);
bytes.writeLong(pair.second);
}
}
}
BytesReader
,
BytesInterop
long size(E e)
bytes
on
write(bytes, e)
call.e
- the object which serialized form length should be returnedvoid write(Bytes bytes, E e)
bytes
, without writing the length of the
serialized form itself.
Implementation of this method should increment the bytes
' position by size(e)
. The given object should
be written into these range between the initial bytes
' position and the position
after this method call returns. Implementation of this method must not alter the
bytes
' limit and contents outside of the specified range.
bytes
- the Bytes
to write the given object toe
- the object to serialize to the given bytesBytesReader.read(Bytes, long)
Copyright © 2014. All rights reserved.