Package org.apache.cassandra.serializers
Class MapSerializer<K,V>
- java.lang.Object
-
- org.apache.cassandra.serializers.TypeSerializer<T>
-
- org.apache.cassandra.serializers.CollectionSerializer<java.util.Map<K,V>>
-
- org.apache.cassandra.serializers.MapSerializer<K,V>
-
public class MapSerializer<K,V> extends CollectionSerializer<java.util.Map<K,V>>
-
-
Field Summary
Fields Modifier and Type Field Description TypeSerializer<K>
keys
TypeSerializer<V>
values
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description <I> java.util.Map<K,V>
deserializeForNativeProtocol(I input, ValueAccessor<I> accessor, ProtocolVersion version)
int
getElementCount(java.util.Map<K,V> value)
static <K,V>
MapSerializer<K,V>getInstance(TypeSerializer<K> keys, TypeSerializer<V> values, ValueComparators comparators)
java.nio.ByteBuffer
getSerializedValue(java.nio.ByteBuffer collection, java.nio.ByteBuffer key, AbstractType<?> comparator)
Extract an element from a serialized collection.java.nio.ByteBuffer
getSliceFromSerialized(java.nio.ByteBuffer collection, java.nio.ByteBuffer from, java.nio.ByteBuffer to, AbstractType<?> comparator, boolean frozen)
Returns the slice of a collection directly from its serialized value.java.lang.Class<java.util.Map<K,V>>
getType()
java.util.List<java.nio.ByteBuffer>
serializeValues(java.util.Map<K,V> map)
java.lang.String
toString(java.util.Map<K,V> value)
<T> void
validateForNativeProtocol(T input, ValueAccessor<T> accessor, ProtocolVersion version)
-
Methods inherited from class org.apache.cassandra.serializers.CollectionSerializer
copyAsNewCollection, deserialize, deserializeForNativeProtocol, pack, pack, readCollectionSize, readCollectionSize, readValue, serialize, sizeOfCollectionSize, sizeOfValue, skipValue, skipValue, validate, writeCollectionSize, writeValue
-
Methods inherited from class org.apache.cassandra.serializers.TypeSerializer
deserialize, toCQLLiteral, validate
-
-
-
-
Field Detail
-
keys
public final TypeSerializer<K> keys
-
values
public final TypeSerializer<V> values
-
-
Method Detail
-
getInstance
public static <K,V> MapSerializer<K,V> getInstance(TypeSerializer<K> keys, TypeSerializer<V> values, ValueComparators comparators)
-
serializeValues
public java.util.List<java.nio.ByteBuffer> serializeValues(java.util.Map<K,V> map)
- Specified by:
serializeValues
in classCollectionSerializer<java.util.Map<K,V>>
-
getElementCount
public int getElementCount(java.util.Map<K,V> value)
- Specified by:
getElementCount
in classCollectionSerializer<java.util.Map<K,V>>
-
validateForNativeProtocol
public <T> void validateForNativeProtocol(T input, ValueAccessor<T> accessor, ProtocolVersion version)
- Specified by:
validateForNativeProtocol
in classCollectionSerializer<java.util.Map<K,V>>
-
deserializeForNativeProtocol
public <I> java.util.Map<K,V> deserializeForNativeProtocol(I input, ValueAccessor<I> accessor, ProtocolVersion version)
- Specified by:
deserializeForNativeProtocol
in classCollectionSerializer<java.util.Map<K,V>>
-
getSerializedValue
public java.nio.ByteBuffer getSerializedValue(java.nio.ByteBuffer collection, java.nio.ByteBuffer key, AbstractType<?> comparator)
Description copied from class:CollectionSerializer
Extract an element from a serialized collection.Note that this is only supported to sets and maps. For sets, this mostly ends up being a check for the presence of the provide key: it will return the key if it's present and
null
otherwise.- Specified by:
getSerializedValue
in classCollectionSerializer<java.util.Map<K,V>>
- Parameters:
collection
- the serialized collection. This cannot benull
.key
- the key to extract (This cannot benull
norByteBufferUtil.UNSET_BYTE_BUFFER
).comparator
- the type to use to compare thekey
value to those in the collection.- Returns:
- the value associated with
key
if one exists,null
otherwise
-
getSliceFromSerialized
public java.nio.ByteBuffer getSliceFromSerialized(java.nio.ByteBuffer collection, java.nio.ByteBuffer from, java.nio.ByteBuffer to, AbstractType<?> comparator, boolean frozen)
Description copied from class:CollectionSerializer
Returns the slice of a collection directly from its serialized value.If the slice contains no elements an empty collection will be returned for frozen collections, and a
null
one for non-frozen collections.- Specified by:
getSliceFromSerialized
in classCollectionSerializer<java.util.Map<K,V>>
- Parameters:
collection
- the serialized collection. This cannot benull
.from
- the left bound of the slice to extract. This cannot benull
but if this isByteBufferUtil.UNSET_BYTE_BUFFER
, then the returned slice starts at the beginning ofcollection
.comparator
- the type to use to compare thefrom
andto
values to those in the collection.frozen
-true
if the collection is a frozen one,false
otherwise- Returns:
- a serialized collection corresponding to slice
[from, to]
ofcollection
.
-
toString
public java.lang.String toString(java.util.Map<K,V> value)
- Specified by:
toString
in classTypeSerializer<java.util.Map<K,V>>
-
-