Class SortedMapSerializer<K extends Comparable<?>, V>
java.lang.Object
pt.unl.fct.di.novasys.babel2.channels.serializers.collections.SortedMapSerializer<K,V>
- Type Parameters:
K- the type of comparable keys in the mapV- the type of values in the map
- All Implemented Interfaces:
BabelNetworkSerializer<SortedMap<K,V>>
public class SortedMapSerializer<K extends Comparable<?>, V>
extends Object
implements BabelNetworkSerializer<SortedMap<K,V>>
Network serializer for Java
SortedMap collections.
Sorted maps are serialized by writing an integer size followed by alternating serialized keys and values.
Upon deserialization, an ImmutableSortedMap with natural ordering is constructed.
-
Constructor Summary
ConstructorsConstructorDescriptionSortedMapSerializer(BabelNetworkSerializer<K> keySerializer, BabelNetworkSerializer<V> valueSerializer) Constructs a new sorted 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(SortedMap<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(SortedMap<K, V> object, @Nullable NodeStore store) Returns a size estimate to fit the entire object in aByteBufwithout needing resizes.
-
Constructor Details
-
SortedMapSerializer
public SortedMapSerializer(BabelNetworkSerializer<K> keySerializer, BabelNetworkSerializer<V> valueSerializer) Constructs a new sorted map serializer using the given key and value serializers.- Parameters:
keySerializer- the serializer for map keysvalueSerializer- the serializer for map values
-
-
Method Details
-
serialize
Description copied from interface:BabelNetworkSerializerEncodesobjectand appends the resulting bytes toout.- Specified by:
serializein interfaceBabelNetworkSerializer<K extends Comparable<?>>- Parameters:
object- the object to serializeout- the destination bufferstore- the node store context for resolving node components
-
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 extends Comparable<?>>- Parameters:
in- the source bufferstore- the node store context for resolving node components- Returns:
- the deserialized object
-
getObjectClass
Description copied from interface:BabelNetworkSerializerReturns the class of objects handled by this serializer, used for registry lookup.- Specified by:
getObjectClassin interfaceBabelNetworkSerializer<K extends Comparable<?>>- Returns:
- the handled class
-
getEstimateSize
Description copied from interface:BabelNetworkSerializerReturns an estimated size in bytes for the given object.- Specified by:
getEstimateSizein interfaceBabelNetworkSerializer<K extends Comparable<?>>- Parameters:
object- the object to estimate- Returns:
- estimated byte size, or 0 if unknown
-