Package org.apache.cassandra.serializers
Class CollectionSerializer<T>
- java.lang.Object
-
- org.apache.cassandra.serializers.TypeSerializer<T>
-
- org.apache.cassandra.serializers.CollectionSerializer<T>
-
- Direct Known Subclasses:
ListSerializer,MapSerializer,SetSerializer
public abstract class CollectionSerializer<T> extends TypeSerializer<T>
-
-
Constructor Summary
Constructors Constructor Description CollectionSerializer()
-
Method Summary
All Methods Static Methods Instance Methods Abstract Methods Concrete Methods Modifier and Type Method Description protected java.nio.ByteBuffercopyAsNewCollection(java.nio.ByteBuffer input, int count, int startPos, int endPos, ProtocolVersion version)Creates a new serialized map composed from the data frominputbetweenstartPos(inclusive) andendPos(exclusive), assuming that data holdscountelements.<V> Tdeserialize(V value, ValueAccessor<V> accessor)TdeserializeForNativeProtocol(java.nio.ByteBuffer value, ProtocolVersion version)abstract <V> TdeserializeForNativeProtocol(V value, ValueAccessor<V> accessor, ProtocolVersion version)protected abstract intgetElementCount(T value)abstract java.nio.ByteBuffergetSerializedValue(java.nio.ByteBuffer collection, java.nio.ByteBuffer key, AbstractType<?> comparator)Extract an element from a serialized collection.abstract java.nio.ByteBuffergetSliceFromSerialized(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.static java.nio.ByteBufferpack(java.util.Collection<java.nio.ByteBuffer> values, int elements, ProtocolVersion version)static <V> Vpack(java.util.Collection<V> values, ValueAccessor<V> accessor, int elements, ProtocolVersion version)static intreadCollectionSize(java.nio.ByteBuffer input, ProtocolVersion version)static <V> intreadCollectionSize(V value, ValueAccessor<V> accessor, ProtocolVersion version)static <V> VreadNonNullValue(V input, ValueAccessor<V> accessor, int offset, ProtocolVersion version)static <V> VreadValue(V input, ValueAccessor<V> accessor, int offset, ProtocolVersion version)java.nio.ByteBufferserialize(T input)protected abstract java.util.List<java.nio.ByteBuffer>serializeValues(T value)static intsizeOfCollectionSize(int elements, ProtocolVersion version)static <V> intsizeOfValue(V value, ValueAccessor<V> accessor, ProtocolVersion version)protected static voidskipValue(java.nio.ByteBuffer input, ProtocolVersion version)static <V> intskipValue(V input, ValueAccessor<V> accessor, int offset, ProtocolVersion version)<T1> voidvalidate(T1 value, ValueAccessor<T1> accessor)abstract <V> voidvalidateForNativeProtocol(V value, ValueAccessor<V> accessor, ProtocolVersion version)protected static voidwriteCollectionSize(java.nio.ByteBuffer output, int elements, ProtocolVersion version)static <V> voidwriteValue(java.nio.ByteBuffer output, V value, ValueAccessor<V> accessor, ProtocolVersion version)-
Methods inherited from class org.apache.cassandra.serializers.TypeSerializer
deserialize, getType, toCQLLiteral, toString, validate
-
-
-
-
Method Detail
-
serializeValues
protected abstract java.util.List<java.nio.ByteBuffer> serializeValues(T value)
-
getElementCount
protected abstract int getElementCount(T value)
-
deserializeForNativeProtocol
public abstract <V> T deserializeForNativeProtocol(V value, ValueAccessor<V> accessor, ProtocolVersion version)
-
deserializeForNativeProtocol
public T deserializeForNativeProtocol(java.nio.ByteBuffer value, ProtocolVersion version)
-
validateForNativeProtocol
public abstract <V> void validateForNativeProtocol(V value, ValueAccessor<V> accessor, ProtocolVersion version)
-
serialize
public java.nio.ByteBuffer serialize(T input)
- Specified by:
serializein classTypeSerializer<T>
-
deserialize
public <V> T deserialize(V value, ValueAccessor<V> accessor)
- Specified by:
deserializein classTypeSerializer<T>
-
validate
public <T1> void validate(T1 value, ValueAccessor<T1> accessor) throws MarshalException- Specified by:
validatein classTypeSerializer<T>- Throws:
MarshalException
-
pack
public static java.nio.ByteBuffer pack(java.util.Collection<java.nio.ByteBuffer> values, int elements, ProtocolVersion version)
-
pack
public static <V> V pack(java.util.Collection<V> values, ValueAccessor<V> accessor, int elements, ProtocolVersion version)
-
writeCollectionSize
protected static void writeCollectionSize(java.nio.ByteBuffer output, int elements, ProtocolVersion version)
-
readCollectionSize
public static int readCollectionSize(java.nio.ByteBuffer input, ProtocolVersion version)
-
readCollectionSize
public static <V> int readCollectionSize(V value, ValueAccessor<V> accessor, ProtocolVersion version)
-
sizeOfCollectionSize
public static int sizeOfCollectionSize(int elements, ProtocolVersion version)
-
writeValue
public static <V> void writeValue(java.nio.ByteBuffer output, V value, ValueAccessor<V> accessor, ProtocolVersion version)
-
readValue
public static <V> V readValue(V input, ValueAccessor<V> accessor, int offset, ProtocolVersion version)
-
readNonNullValue
public static <V> V readNonNullValue(V input, ValueAccessor<V> accessor, int offset, ProtocolVersion version)
-
skipValue
protected static void skipValue(java.nio.ByteBuffer input, ProtocolVersion version)
-
skipValue
public static <V> int skipValue(V input, ValueAccessor<V> accessor, int offset, ProtocolVersion version)
-
sizeOfValue
public static <V> int sizeOfValue(V value, ValueAccessor<V> accessor, ProtocolVersion version)
-
getSerializedValue
public abstract java.nio.ByteBuffer getSerializedValue(java.nio.ByteBuffer collection, java.nio.ByteBuffer key, AbstractType<?> comparator)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
nullotherwise.- Parameters:
collection- the serialized collection. This cannot benull.key- the key to extract (This cannot benullnorByteBufferUtil.UNSET_BYTE_BUFFER).comparator- the type to use to compare thekeyvalue to those in the collection.- Returns:
- the value associated with
keyif one exists,nullotherwise
-
getSliceFromSerialized
public abstract 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.If the slice contains no elements an empty collection will be returned for frozen collections, and a
nullone for non-frozen collections.- Parameters:
collection- the serialized collection. This cannot benull.from- the left bound of the slice to extract. This cannot benullbut if this isByteBufferUtil.UNSET_BYTE_BUFFER, then the returned slice starts at the beginning ofcollection.comparator- the type to use to compare thefromandtovalues to those in the collection.frozen-trueif the collection is a frozen one,falseotherwise- Returns:
- a serialized collection corresponding to slice
[from, to]ofcollection.
-
copyAsNewCollection
protected java.nio.ByteBuffer copyAsNewCollection(java.nio.ByteBuffer input, int count, int startPos, int endPos, ProtocolVersion version)Creates a new serialized map composed from the data frominputbetweenstartPos(inclusive) andendPos(exclusive), assuming that data holdscountelements.
-
-