Class KvStateSerializer


  • public final class KvStateSerializer
    extends Object
    Serialization and deserialization the different state types and namespaces.
    • Constructor Detail

      • KvStateSerializer

        public KvStateSerializer()
    • 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 a ByteBuffer.

        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 type
        N - Namespace type
        Parameters:
        key - Key to serialize
        keySerializer - Serializer for the key
        namespace - Namespace to serialize
        namespaceSerializer - 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 a Tuple2.
        Type Parameters:
        K - Key type
        N - Namespace
        Parameters:
        serializedKeyAndNamespace - Serialized key and namespace
        keySerializer - Serializer for the key
        namespaceSerializer - 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 serialize
        serializer - Serializer for T
        Returns:
        Serialized value or null if value null
        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 T
        serializer - Serializer for T
        Returns:
        Deserialized value or null if the serialized value is null
        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 is null
        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 keys
        UV - Type of the values
        Parameters:
        entries - Key-value pairs to serialize
        keySerializer - Serializer for UK
        valueSerializer - Serializer for UV
        Returns:
        Serialized values or null if values null 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 key
        UV - Type of the value.
        Parameters:
        serializedValue - Serialized value of type Map<UK, UV>
        keySerializer - Serializer for UK
        valueSerializer - Serializer for UV
        Returns:
        Deserialized map or null if the serialized value is null
        Throws:
        IOException - On failure during deserialization