Package com.apple.foundationdb.map
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 Summary
Modifier and TypeMethodDescriptionbooleanReturnstrue.deserializeEntries(Tuple key, byte[] data) Deserialize raw data to a list of entries.deserializeKey(byte[] data, int offset, int length) Deserialize a slice of a byte array into a key.static BunchedTupleSerializerinstance()Get the serializer singleton.byte[]serializeEntries(List<Map.Entry<Tuple, Tuple>> entries) Serialize an entry list to bytes.byte[]serializeEntry(Tuple key, Tuple value) Serialize a pair ofTuples to bytes.byte[]serializeKey(Tuple key) Serialize aTupleto bytes.Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, waitMethods inherited from interface com.apple.foundationdb.map.BunchedSerializer
deserializeKey, deserializeKey, deserializeKeys, serializeEntry
-
Method Details
-
instance
Get the serializer singleton.- Returns:
- the
BunchedTupleSerializersingleton
-
serializeKey
Serialize aTupleto bytes. This uses the standard Tuple packing function to do so.- Specified by:
serializeKeyin interfaceBunchedSerializer<Tuple,Tuple> - Parameters:
key- key to serialize to bytes- Returns:
- the serialized key
-
serializeEntry
Serialize a pair ofTuples to bytes. This packs eachTupleas nestedTuples and then returns the concatenated bytes. AscanAppend()returnstrue, this can be used to append an element to the end of an entry list.- Specified by:
serializeEntryin interfaceBunchedSerializer<Tuple,Tuple> - Parameters:
key- the key of the map entryvalue- the value of the map entry- Returns:
- the serialized entry
-
serializeEntries
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:
serializeEntriesin interfaceBunchedSerializer<Tuple,Tuple> - Parameters:
entries- the list of entries to serialize- Returns:
- the serialized entry list
-
deserializeKey
Description copied from interface:BunchedSerializerDeserialize a slice of a byte array into a key. This will only deserialize the portion of the array starting atoffsetand going forlengthbytes.- Specified by:
deserializeKeyin interfaceBunchedSerializer<Tuple,Tuple> - Parameters:
data- source data to deserializeoffset- 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:BunchedSerializerDeserialize raw data to a list of entries. This should be the inverse ofserializeEntries. 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:
deserializeEntriesin interfaceBunchedSerializer<Tuple,Tuple> - Parameters:
key- key under which the serialized entry list was storeddata- source list to deserialize- Returns:
- entry list deserialized from reading
data
-
canAppend
public boolean canAppend()Returnstrue. 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:
canAppendin interfaceBunchedSerializer<Tuple,Tuple> - Returns:
trueas this serialization format supports appending
-