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 Tuple
s 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 TypeMethodDescriptionboolean
Returnstrue
.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 BunchedTupleSerializer
instance()
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 ofTuple
s to bytes.byte[]
serializeKey
(Tuple key) Serialize aTuple
to bytes.Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
Methods inherited from interface com.apple.foundationdb.map.BunchedSerializer
deserializeKey, deserializeKey, deserializeKeys, serializeEntry
-
Method Details
-
instance
Get the serializer singleton.- Returns:
- the
BunchedTupleSerializer
singleton
-
serializeKey
Serialize aTuple
to bytes. This uses the standard Tuple packing function to do so.- Specified by:
serializeKey
in interfaceBunchedSerializer<Tuple,
Tuple> - Parameters:
key
- key to serialize to bytes- Returns:
- the serialized key
-
serializeEntry
Serialize a pair ofTuple
s to bytes. This packs eachTuple
as nestedTuple
s 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:
serializeEntry
in 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:
serializeEntries
in interfaceBunchedSerializer<Tuple,
Tuple> - Parameters:
entries
- the list of entries to serialize- Returns:
- the serialized entry list
-
deserializeKey
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 atoffset
and going forlength
bytes.- Specified by:
deserializeKey
in 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:BunchedSerializer
Deserialize 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:
deserializeEntries
in 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:
canAppend
in interfaceBunchedSerializer<Tuple,
Tuple> - Returns:
true
as this serialization format supports appending
-