Class MapSerializer<K,V>
java.lang.Object
pt.unl.fct.di.novasys.babel2.channels.serializers.collections.MapSerializer<K,V>
- Type Parameters:
K- the type of keys in the mapV- the type of values in the map
- All Implemented Interfaces:
BabelNetworkSerializer<Map<K,V>>
Network serializer for Java
Map collections.
Maps are serialized by writing an integer size followed by alternating serialized keys and values.
Upon deserialization, an ImmutableMap is constructed.
-
Constructor Summary
ConstructorsConstructorDescriptionMapSerializer(BabelNetworkSerializer<K> keySerializer, BabelNetworkSerializer<V> valueSerializer) Constructs a new map serializer using the given key and value serializers. -
Method Summary
Modifier and TypeMethodDescriptiondeserialize(io.netty.buffer.ByteBuf in, NodeStore store) Reads an instance ofTfrom the supplied buffer.intgetEstimateSize(Map<K, V> object) Returns an estimated size in bytes for the given object.Returns the class of objects handled by this serializer, used for registry lookup.voidEncodesobjectand appends the resulting bytes toout.Methods inherited from class Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, waitMethods inherited from interface BabelNetworkSerializer
getEstimateSizeModifier and TypeMethodDescriptiondefault intgetEstimateSize(Map<K, V> object, @Nullable NodeStore store) Returns a size estimate to fit the entire object in aByteBufwithout needing resizes.
-
Constructor Details
-
MapSerializer
public MapSerializer(BabelNetworkSerializer<K> keySerializer, BabelNetworkSerializer<V> valueSerializer) Constructs a new map serializer using the given key and value serializers.- Parameters:
keySerializer- the serializer for map keysvalueSerializer- the serializer for map values
-
-
Method Details
-
deserialize
Description copied from interface:BabelNetworkSerializerReads an instance ofTfrom the supplied buffer. The buffer's reader index must be positioned at the first byte of the encoded object. Upon return the reader index is advanced past all bytes consumed.- Specified by:
deserializein interfaceBabelNetworkSerializer<K>- Parameters:
in- the source bufferstore- the node store context for resolving node components- Returns:
- the deserialized object
-
serialize
Description copied from interface:BabelNetworkSerializerEncodesobjectand appends the resulting bytes toout.- Specified by:
serializein interfaceBabelNetworkSerializer<K>- Parameters:
object- the object to serializeout- the destination bufferstore- the node store context for resolving node components
-
getObjectClass
Description copied from interface:BabelNetworkSerializerReturns the class of objects handled by this serializer, used for registry lookup.- Specified by:
getObjectClassin interfaceBabelNetworkSerializer<K>- Returns:
- the handled class
-
getEstimateSize
Description copied from interface:BabelNetworkSerializerReturns an estimated size in bytes for the given object.- Specified by:
getEstimateSizein interfaceBabelNetworkSerializer<K>- Parameters:
object- the object to estimate- Returns:
- estimated byte size, or 0 if unknown
-