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
-
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionprotected ByteBuffercopyAsNewCollection(ByteBuffer input, int count, int startPos, int endPos) Creates a new serialized map composed from the data frominputbetweenstartPos(inclusive) andendPos(exclusive), assuming that data holdscountelements.voidforEach(ByteBuffer input, Consumer<ByteBuffer> action) protected abstract intgetElementCount(T value) abstract com.google.common.collect.Range<Integer>getIndexesRangeFromSerialized(ByteBuffer collection, ByteBuffer from, ByteBuffer to, AbstractType<?> comparator) Returns the range of indexes corresponding to the specified range of elements in the serialized collection.abstract intgetIndexFromSerialized(ByteBuffer collection, ByteBuffer key, AbstractType<?> comparator) Returns the index of an element in a serialized collection.abstract ByteBuffergetSerializedValue(ByteBuffer collection, ByteBuffer key, AbstractType<?> comparator) Extract an element from a serialized collection.abstract ByteBuffergetSliceFromSerialized(ByteBuffer collection, ByteBuffer from, ByteBuffer to, AbstractType<?> comparator, boolean frozen) Returns the slice of a collection directly from its serialized value.static ByteBufferpack(Collection<ByteBuffer> values, int elements) static <V> Vpack(Collection<V> values, ValueAccessor<V> accessor, int elements) static <V> intreadCollectionSize(V value, ValueAccessor<V> accessor) static <V> VreadNonNullValue(V input, ValueAccessor<V> accessor, int offset) static <V> VreadValue(V input, ValueAccessor<V> accessor, int offset) protected abstract List<ByteBuffer>serializeValues(T value) static intstatic <V> intsizeOfValue(V value, ValueAccessor<V> accessor) protected static voidskipValue(ByteBuffer input) static <V> intskipValue(V input, ValueAccessor<V> accessor, int offset) protected static voidwriteCollectionSize(ByteBuffer output, int elements) static <V> voidwriteValue(ByteBuffer output, V value, ValueAccessor<V> accessor) Methods inherited from class org.apache.cassandra.serializers.TypeSerializer
deserialize, deserialize, getType, isNull, isNull, shouldQuoteCQLLiterals, toCQLLiteral, toCQLLiteralNonNull, toCQLLiteralNoQuote, toString, validate, validate
-
Constructor Details
-
CollectionSerializer
public CollectionSerializer()
-
-
Method Details
-
serializeValues
-
getElementCount
-
serialize
- Specified by:
serializein classTypeSerializer<T>
-
pack
-
pack
-
writeCollectionSize
-
readCollectionSize
-
sizeOfCollectionSize
public static int sizeOfCollectionSize() -
writeValue
-
readValue
-
readNonNullValue
-
skipValue
-
skipValue
-
sizeOfValue
-
getSerializedValue
public abstract ByteBuffer getSerializedValue(ByteBuffer collection, 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 ByteBuffer getSliceFromSerialized(ByteBuffer collection, ByteBuffer from, 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.
-
getIndexFromSerialized
public abstract int getIndexFromSerialized(ByteBuffer collection, ByteBuffer key, AbstractType<?> comparator) Returns the index of an element in a serialized collection.Note that this is only supported by sets and maps, but not by lists.
- Parameters:
collection- The serialized collection. This cannot benull.key- The key for which the index must be found. This cannot benullnorByteBufferUtil.UNSET_BYTE_BUFFER).comparator- The type to use to compare thekeyvalue to those in the collection.- Returns:
- The index of the element associated with
keyif one exists,-1otherwise.
-
getIndexesRangeFromSerialized
public abstract com.google.common.collect.Range<Integer> getIndexesRangeFromSerialized(ByteBuffer collection, ByteBuffer from, ByteBuffer to, AbstractType<?> comparator) Returns the range of indexes corresponding to the specified range of elements in the serialized collection.Note that this is only supported by sets and maps, but not by lists.
- 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 of the collection.to- The left bound of the slice to extract. This cannot benullbut if this isByteBufferUtil.UNSET_BYTE_BUFFER, then the returned slice ends at the end of the collection.comparator- The type to use to compare thefromandtovalues to those in the collection.- Returns:
- The range of indexes corresponding to specified range of elements.
-
copyAsNewCollection
Creates a new serialized map composed from the data frominputbetweenstartPos(inclusive) andendPos(exclusive), assuming that data holdscountelements. -
forEach
-