Class BunchedTupleSerializer

java.lang.Object
com.apple.foundationdb.map.BunchedTupleSerializer
All Implemented Interfaces:
BunchedSerializer<Tuple,Tuple>

@API(EXPERIMENTAL) public class BunchedTupleSerializer extends Object implements BunchedSerializer<Tuple,Tuple>
A BunchedSerializer that uses Tuples as both the expected key and value type. This uses the ability of Tuple classes to pack themselves in a fairly straightforward way. This will do the right thing, but it can be somewhat space inefficient when serializing an entry as the Tuple encoding is designed to preserve order, which is unnecessary for values.
  • Method Details

    • instance

      public static BunchedTupleSerializer instance()
      Get the serializer singleton.
      Returns:
      the BunchedTupleSerializer singleton
    • serializeKey

      @Nonnull public byte[] serializeKey(@Nonnull Tuple key)
      Serialize a Tuple to bytes. This uses the standard Tuple packing function to do so.
      Specified by:
      serializeKey in interface BunchedSerializer<Tuple,Tuple>
      Parameters:
      key - key to serialize to bytes
      Returns:
      the serialized key
    • serializeEntry

      @Nonnull public byte[] serializeEntry(@Nonnull Tuple key, @Nonnull Tuple value)
      Serialize a pair of Tuples to bytes. This packs each Tuple as nested Tuples and then returns the concatenated bytes. As canAppend() returns true, this can be used to append an element to the end of an entry list.
      Specified by:
      serializeEntry in interface BunchedSerializer<Tuple,Tuple>
      Parameters:
      key - the key of the map entry
      value - the value of the map entry
      Returns:
      the serialized entry
    • serializeEntries

      @Nonnull public byte[] serializeEntries(@Nonnull List<Map.Entry<Tuple,Tuple>> entries)
      Serialize an entry list to bytes. This will place a prefix at the beginning of the list in order to support versioning of the entry list data structure in the future. Otherwise, it concatenates serialized entries together.
      Specified by:
      serializeEntries in interface BunchedSerializer<Tuple,Tuple>
      Parameters:
      entries - the list of entries to serialize
      Returns:
      the serialized entry list
    • deserializeKey

      @Nonnull public Tuple deserializeKey(@Nonnull byte[] data, int offset, int length)
      Description copied from interface: BunchedSerializer
      Deserialize a slice of a byte array into a key. This will only deserialize the portion of the array starting at offset and going for length bytes.
      Specified by:
      deserializeKey in interface BunchedSerializer<Tuple,Tuple>
      Parameters:
      data - source data to deserialize
      offset - beginning offset of serialized key (indexed from 0)
      length - length of serialized key
      Returns:
      key deserialized from reading data
    • deserializeEntries

      @Nonnull public List<Map.Entry<Tuple,Tuple>> deserializeEntries(@Nonnull Tuple key, @Nonnull byte[] data)
      Description copied from interface: BunchedSerializer
      Deserialize raw data to a list of entries. This should be the inverse of serializeEntries. Note that the order of elements returned within the list should be the same as their sort order. The key that this entry list is stored under is passed in so that implementations that wish to can choose to omit the first key of the entry list from the serialized value.
      Specified by:
      deserializeEntries in interface BunchedSerializer<Tuple,Tuple>
      Parameters:
      key - key under which the serialized entry list was stored
      data - source list to deserialize
      Returns:
      entry list deserialized from reading data
    • canAppend

      public boolean canAppend()
      Returns true. This format supports appending serialized entries to the end of a serialized entry list to create the serialized bytes of the original list with the new entry at the end.
      Specified by:
      canAppend in interface BunchedSerializer<Tuple,Tuple>
      Returns:
      true as this serialization format supports appending