T - the element type of serialized Listspublic final class ListMarshaller<T> extends Object implements BytesReader<List<T>>, BytesWriter<List<T>>, StatefulCopyable<ListMarshaller<T>>
List<T>. Uses ArrayList as the list implementation to deserialize
into.
This marshaller supports multimap emulation on top of Chronicle Map, that is possible but inefficient. See the README section.
Usage:
ChronicleMap<String, List<Integer>> regNumbers = ChronicleMap
.of(String.class, (Class<List<Integer>>) (Class) List.class)
.averageKey("John Smith")
.valueMarshaller(ListMarshaller.of(IntegerMarshaller.INSTANCE))
.averageValue(ImmutableList.of(1, 2, 3))
.entries(10_000)
.create();
Look for pre-defined element marshallers in net.openhft.chronicle.hash.serialization.impl package. This package is not included into
Javadocs, but present in Chronicle Map distribution. If there are no existing marshallers for
your List element type, define BytesReader and BytesWriter yourself.
SetMarshaller,
MapMarshaller| Constructor and Description |
|---|
ListMarshaller(BytesReader<T> elementReader,
BytesWriter<? super T> elementWriter)
Constructs a
ListMarshaller with the given list elements' serializers. |
| Modifier and Type | Method and Description |
|---|---|
ListMarshaller<T> |
copy()
Creates a copy of this marshaller, with independent state.
|
static <T> ListMarshaller<T> |
of(BytesReader<T> elementReader,
BytesWriter<? super T> elementWriter)
Returns a
ListMarshaller which uses the given list elements' serializers. |
static <T,M extends BytesReader<T> & BytesWriter<? super T>> |
of(M elementMarshaller)
Returns a
ListMarshaller which uses the given marshaller as both reader and writer of
list elements. |
List<T> |
read(net.openhft.chronicle.bytes.Bytes in,
List<T> using)
Reads and returns the object from
RandomCommon.readPosition() (i. |
void |
readMarshallable(net.openhft.chronicle.wire.WireIn wireIn) |
void |
write(net.openhft.chronicle.bytes.Bytes out,
List<T> toWrite)
Serializes the given object to the given
out. |
void |
writeMarshallable(net.openhft.chronicle.wire.WireOut wireOut) |
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait$equals, $fieldInfos, $hashCode, $toString, copyFrom, copyTo, deepCopy, fromFile, fromFile, fromFileAsMap, fromFileAsMap, fromHexString, fromString, fromString, fromString, getClassName, getField, mergeToMap, reset, setField, streamFromFile, streamFromFilecopyIfNeededpublic ListMarshaller(BytesReader<T> elementReader, BytesWriter<? super T> elementWriter)
ListMarshaller with the given list elements' serializers.
Use static factory of(BytesReader, BytesWriter) instead of this constructor
directly.
elementReader - list elements' readerelementWriter - list elements' writerpublic static <T> ListMarshaller<T> of(BytesReader<T> elementReader, BytesWriter<? super T> elementWriter)
ListMarshaller which uses the given list elements' serializers.T - type of list elementselementReader - list elements' readerelementWriter - list elements' writerListMarshaller which uses the given list elements' serializerspublic static <T,M extends BytesReader<T> & BytesWriter<? super T>> ListMarshaller<T> of(M elementMarshaller)
ListMarshaller which uses the given marshaller as both reader and writer of
list elements. Example:
ChronicleMap
.of(String.class, (Class<List<Integer>>) ((Class) List.class))
.valueMarshaller(ListMarshaller.of(IntegerMarshaller.INSTANCE))
...T - type of list elementsM - type of list elements' marshallerelementMarshaller - list elements' marshallerListMarshaller which uses the given list elements' marshaller@NotNull public List<T> read(net.openhft.chronicle.bytes.Bytes in, @Nullable List<T> using)
BytesReaderRandomCommon.readPosition() (i. e. the current position)
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 object then
returned from this method back. 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, i. e. consume the
read bytes. in bytes shouldn't be written.
read in interface BytesReader<List<T>>in - the Bytes to read the object fromusing - the object to read the deserialized data into, could be nullpublic void write(net.openhft.chronicle.bytes.Bytes out,
@NotNull
List<T> toWrite)
BytesWriterout.
Implementation of this method should increment the position of the given out by the number of bytes written. The given object should be
written into these range between the initial bytes' position and the position after
this method call returns. Bytes outside of this range shouldn't be written. Any bytes
shouldn't be read from out.
write in interface BytesWriter<List<T>>out - the Bytes to write the given object totoWrite - the object to serializepublic ListMarshaller<T> copy()
StatefulCopyablecopy() is called, should be inherited in the copy (e. g. the class of objects
serialized). So, copy() should be transitive, i. e. marshaller.copy() and
marshaller.copy().copy() should result to identical instances.
The state of the instance on which copy() is called shouldn't be changed.
If some marshaller is ought to implement StatefulCopyable interface (e. g.
DataAccess) but is stateless actually, it could return this from this method.
copy in interface StatefulCopyable<ListMarshaller<T>>public void readMarshallable(@NotNull
net.openhft.chronicle.wire.WireIn wireIn)
readMarshallable in interface net.openhft.chronicle.wire.MarshallablereadMarshallable in interface net.openhft.chronicle.wire.ReadMarshallablepublic void writeMarshallable(@NotNull
net.openhft.chronicle.wire.WireOut wireOut)
writeMarshallable in interface net.openhft.chronicle.wire.MarshallablewriteMarshallable in interface net.openhft.chronicle.wire.WriteMarshallableCopyright © 2019. All rights reserved.