K
- the key type of serialized MapsV
- the value type of serialized Mapspublic final class MapMarshaller<K,V> extends Object implements BytesReader<Map<K,V>>, BytesWriter<Map<K,V>>, StatefulCopyable<MapMarshaller<K,V>>
Map<K, V>
. Uses HashMap
(hence default key objects' equality and
hashCode()
as the map implementation to deserialize into.
This marshaller supports multimap emulation on top of Chronicle Map, that is possible but inefficient. See the README section.
Look for pre-defined key and value marshallers in the
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 Map
key or value types, define BytesReader
and BytesWriter
yourself.
ListMarshaller
,
SetMarshaller
Constructor and Description |
---|
MapMarshaller(BytesReader<K> keyReader,
BytesWriter<? super K> keyWriter,
BytesReader<V> valueReader,
BytesWriter<? super V> valueWriter)
Constructs a
MapMarshaller with the given map keys' and values' serializers. |
Modifier and Type | Method and Description |
---|---|
MapMarshaller<K,V> |
copy()
Creates a copy of this marshaller, with independent state.
|
Map<K,V> |
read(net.openhft.chronicle.bytes.Bytes in,
Map<K,V> 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,
Map<K,V> 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, $fieldInfoMap, $fieldInfos, $hashCode, $toString, className, copyTo, deepCopy, fromFile, fromFile, fromString, fromString, fromString, getField, getLongField, mergeToMap, reset, setField, setLongField, streamFromFile, streamFromFile
binaryLengthLength, writeValue
usesSelfDescribingMessage
copyIfNeeded
public MapMarshaller(BytesReader<K> keyReader, BytesWriter<? super K> keyWriter, BytesReader<V> valueReader, BytesWriter<? super V> valueWriter)
MapMarshaller
with the given map keys' and values' serializers.keyReader
- map keys' readerkeyWriter
- map keys' writervalueReader
- map values' readervalueWriter
- map values' writer@NotNull public Map<K,V> read(net.openhft.chronicle.bytes.Bytes in, @Nullable Map<K,V> using)
BytesReader
RandomCommon.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<Map<K,V>>
in
- the Bytes
to read the object fromusing
- the object to read the deserialized data into, could be null
public void write(net.openhft.chronicle.bytes.Bytes out, @NotNull Map<K,V> toWrite)
BytesWriter
out
.
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<Map<K,V>>
out
- the Bytes
to write the given object totoWrite
- the object to serializepublic MapMarshaller<K,V> copy()
StatefulCopyable
copy()
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<MapMarshaller<K,V>>
public void readMarshallable(@NotNull net.openhft.chronicle.wire.WireIn wireIn)
readMarshallable
in interface net.openhft.chronicle.wire.Marshallable
readMarshallable
in interface net.openhft.chronicle.wire.ReadMarshallable
public void writeMarshallable(@NotNull net.openhft.chronicle.wire.WireOut wireOut)
writeMarshallable
in interface net.openhft.chronicle.wire.Marshallable
writeMarshallable
in interface net.openhft.chronicle.wire.WriteMarshallable
Copyright © 2023. All rights reserved.