@API(value=EXPERIMENTAL) public class BunchedTupleSerializer extends Object implements BunchedSerializer<Tuple,Tuple>
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.Modifier and Type | Method and Description |
---|---|
boolean |
canAppend()
Returns
true . |
List<Map.Entry<Tuple,Tuple>> |
deserializeEntries(Tuple key,
byte[] data)
Deserialize raw data to a list of entries.
|
Tuple |
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 of
Tuple s to bytes. |
byte[] |
serializeKey(Tuple key)
Serialize a
Tuple to bytes. |
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
deserializeKey, deserializeKey, deserializeKeys, serializeEntry
public static BunchedTupleSerializer instance()
BunchedTupleSerializer
singleton@Nonnull public byte[] serializeKey(@Nonnull Tuple key)
Tuple
to bytes. This uses the standard Tuple
packing function to do so.serializeKey
in interface BunchedSerializer<Tuple,Tuple>
key
- key to serialize to bytes@Nonnull public byte[] serializeEntry(@Nonnull Tuple key, @Nonnull Tuple value)
Tuple
s to bytes. This packs each Tuple
as nested Tuple
s 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.serializeEntry
in interface BunchedSerializer<Tuple,Tuple>
key
- the key of the map entryvalue
- the value of the map entry@Nonnull public byte[] serializeEntries(@Nonnull List<Map.Entry<Tuple,Tuple>> entries)
serializeEntries
in interface BunchedSerializer<Tuple,Tuple>
entries
- the list of entries to serialize@Nonnull public Tuple deserializeKey(@Nonnull byte[] data, int offset, int length)
BunchedSerializer
offset
and going for length
bytes.deserializeKey
in interface BunchedSerializer<Tuple,Tuple>
data
- source data to deserializeoffset
- beginning offset of serialized key (indexed from 0)length
- length of serialized keydata
@Nonnull public List<Map.Entry<Tuple,Tuple>> deserializeEntries(@Nonnull Tuple key, @Nonnull byte[] data)
BunchedSerializer
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.deserializeEntries
in interface BunchedSerializer<Tuple,Tuple>
key
- key under which the serialized entry list was storeddata
- source list to deserializedata
public boolean canAppend()
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.canAppend
in interface BunchedSerializer<Tuple,Tuple>
true
as this serialization format supports appending