Class KvStateSerializer
- java.lang.Object
-
- org.apache.flink.queryablestate.client.state.serialization.KvStateSerializer
-
public final class KvStateSerializer extends Object
Serialization and deserialization the different state types and namespaces.
-
-
Constructor Summary
Constructors Constructor Description KvStateSerializer()
-
Method Summary
All Methods Static Methods Concrete Methods Modifier and Type Method Description static <K,N>
Tuple2<K,N>deserializeKeyAndNamespace(byte[] serializedKeyAndNamespace, TypeSerializer<K> keySerializer, TypeSerializer<N> namespaceSerializer)
Deserializes the key and namespace into aTuple2
.static <T> List<T>
deserializeList(byte[] serializedValue, TypeSerializer<T> serializer)
Deserializes all values with the given serializer.static <UK,UV>
Map<UK,UV>deserializeMap(byte[] serializedValue, TypeSerializer<UK> keySerializer, TypeSerializer<UV> valueSerializer)
Deserializes all kv pairs with the given serializer.static <T> T
deserializeValue(byte[] serializedValue, TypeSerializer<T> serializer)
Deserializes the value with the given serializer.static <K,N>
byte[]serializeKeyAndNamespace(K key, TypeSerializer<K> keySerializer, N namespace, TypeSerializer<N> namespaceSerializer)
Serializes the key and namespace into aByteBuffer
.static <UK,UV>
byte[]serializeMap(Iterable<Map.Entry<UK,UV>> entries, TypeSerializer<UK> keySerializer, TypeSerializer<UV> valueSerializer)
Serializes all values of the Iterable with the given serializer.static <T> byte[]
serializeValue(T value, TypeSerializer<T> serializer)
Serializes the value with the given serializer.
-
-
-
Method Detail
-
serializeKeyAndNamespace
public static <K,N> byte[] serializeKeyAndNamespace(K key, TypeSerializer<K> keySerializer, N namespace, TypeSerializer<N> namespaceSerializer) throws IOException
Serializes the key and namespace into aByteBuffer
.The serialized format matches the RocksDB state backend key format, i.e. the key and namespace don't have to be deserialized for RocksDB lookups.
- Type Parameters:
K
- Key typeN
- Namespace type- Parameters:
key
- Key to serializekeySerializer
- Serializer for the keynamespace
- Namespace to serializenamespaceSerializer
- Serializer for the namespace- Returns:
- Buffer holding the serialized key and namespace
- Throws:
IOException
- Serialization errors are forwarded
-
deserializeKeyAndNamespace
public static <K,N> Tuple2<K,N> deserializeKeyAndNamespace(byte[] serializedKeyAndNamespace, TypeSerializer<K> keySerializer, TypeSerializer<N> namespaceSerializer) throws IOException
Deserializes the key and namespace into aTuple2
.- Type Parameters:
K
- Key typeN
- Namespace- Parameters:
serializedKeyAndNamespace
- Serialized key and namespacekeySerializer
- Serializer for the keynamespaceSerializer
- Serializer for the namespace- Returns:
- Tuple2 holding deserialized key and namespace
- Throws:
IOException
- if the deserialization fails for any reason
-
serializeValue
public static <T> byte[] serializeValue(T value, TypeSerializer<T> serializer) throws IOException
Serializes the value with the given serializer.- Type Parameters:
T
- Type of the value- Parameters:
value
- Value of type T to serializeserializer
- Serializer for T- Returns:
- Serialized value or
null
if valuenull
- Throws:
IOException
- On failure during serialization
-
deserializeValue
public static <T> T deserializeValue(byte[] serializedValue, TypeSerializer<T> serializer) throws IOException
Deserializes the value with the given serializer.- Type Parameters:
T
- Type of the value- Parameters:
serializedValue
- Serialized value of type Tserializer
- Serializer for T- Returns:
- Deserialized value or
null
if the serialized value isnull
- Throws:
IOException
- On failure during deserialization
-
deserializeList
public static <T> List<T> deserializeList(byte[] serializedValue, TypeSerializer<T> serializer) throws IOException
Deserializes all values with the given serializer.- Type Parameters:
T
- Type of the value- Parameters:
serializedValue
- Serialized value of type List<T>serializer
- Serializer for T- Returns:
- Deserialized list or
null
if the serialized value isnull
- Throws:
IOException
- On failure during deserialization
-
serializeMap
public static <UK,UV> byte[] serializeMap(Iterable<Map.Entry<UK,UV>> entries, TypeSerializer<UK> keySerializer, TypeSerializer<UV> valueSerializer) throws IOException
Serializes all values of the Iterable with the given serializer.- Type Parameters:
UK
- Type of the keysUV
- Type of the values- Parameters:
entries
- Key-value pairs to serializekeySerializer
- Serializer for UKvalueSerializer
- Serializer for UV- Returns:
- Serialized values or
null
if valuesnull
or empty - Throws:
IOException
- On failure during serialization
-
deserializeMap
public static <UK,UV> Map<UK,UV> deserializeMap(byte[] serializedValue, TypeSerializer<UK> keySerializer, TypeSerializer<UV> valueSerializer) throws IOException
Deserializes all kv pairs with the given serializer.- Type Parameters:
UK
- Type of the keyUV
- Type of the value.- Parameters:
serializedValue
- Serialized value of type Map<UK, UV>keySerializer
- Serializer for UKvalueSerializer
- Serializer for UV- Returns:
- Deserialized map or
null
if the serialized value isnull
- Throws:
IOException
- On failure during deserialization
-
-