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 Details

    • CollectionSerializer

      public CollectionSerializer()
  • Method Details

    • serializeValues

      protected abstract List<ByteBuffer> serializeValues(T value)
    • getElementCount

      protected abstract int getElementCount(T value)
    • serialize

      public ByteBuffer serialize(T input)
      Specified by:
      serialize in class TypeSerializer<T>
    • pack

      public static ByteBuffer pack(Collection<ByteBuffer> values, int elements)
    • pack

      public static <V> V pack(Collection<V> values, ValueAccessor<V> accessor, int elements)
    • writeCollectionSize

      protected static void writeCollectionSize(ByteBuffer output, int elements)
    • readCollectionSize

      public static <V> int readCollectionSize(V value, ValueAccessor<V> accessor)
    • sizeOfCollectionSize

      public static int sizeOfCollectionSize()
    • writeValue

      public static <V> void writeValue(ByteBuffer output, V value, ValueAccessor<V> accessor)
    • readValue

      public static <V> V readValue(V input, ValueAccessor<V> accessor, int offset)
    • readNonNullValue

      public static <V> V readNonNullValue(V input, ValueAccessor<V> accessor, int offset)
    • skipValue

      protected static void skipValue(ByteBuffer input)
    • skipValue

      public static <V> int skipValue(V input, ValueAccessor<V> accessor, int offset)
    • sizeOfValue

      public static <V> int sizeOfValue(V value, ValueAccessor<V> accessor)
    • 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 null otherwise.

      Parameters:
      collection - the serialized collection. This cannot be null.
      key - the key to extract (This cannot be null nor ByteBufferUtil.UNSET_BYTE_BUFFER).
      comparator - the type to use to compare the key value to those in the collection.
      Returns:
      the value associated with key if one exists, null otherwise
    • 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 null one for non-frozen collections.

      Parameters:
      collection - the serialized collection. This cannot be null.
      from - the left bound of the slice to extract. This cannot be null but if this is ByteBufferUtil.UNSET_BYTE_BUFFER, then the returned slice starts at the beginning of collection.
      comparator - the type to use to compare the from and to 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] of collection.
    • 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 be null.
      key - The key for which the index must be found. This cannot be null nor ByteBufferUtil.UNSET_BYTE_BUFFER).
      comparator - The type to use to compare the key value to those in the collection.
      Returns:
      The index of the element associated with key if one exists, -1 otherwise.
    • 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 be null.
      from - The left bound of the slice to extract. This cannot be null but if this is ByteBufferUtil.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 be null but if this is ByteBufferUtil.UNSET_BYTE_BUFFER, then the returned slice ends at the end of the collection.
      comparator - The type to use to compare the from and to values to those in the collection.
      Returns:
      The range of indexes corresponding to specified range of elements.
    • copyAsNewCollection

      protected ByteBuffer copyAsNewCollection(ByteBuffer input, int count, int startPos, int endPos)
      Creates a new serialized map composed from the data from input between startPos (inclusive) and endPos (exclusive), assuming that data holds count elements.
    • forEach

      public void forEach(ByteBuffer input, Consumer<ByteBuffer> action)