Package org.apache.storm.state

## Class DefaultStateEncoder<K,​V>

- java.lang.Object
- - org.apache.storm.state.DefaultStateEncoder<K,​V>

- All Implemented Interfaces:
    `StateEncoder<K,​V,​byte[],​byte[]>`

      public class DefaultStateEncoder<K,​V>
      extends Object
      implements StateEncoder<K,​V,​byte[],​byte[]>

  Default state encoder class for encoding/decoding key values. This class assumes encoded types of key and value are both binary (byte array) due to keep backward compatibility.

- - ### Field Summary

    Fields
    Modifier and Type | Field | Description
    --- | --- | ---
    `static Serializer<Optional<byte[]>>` | `INTERNAL_VALUE_SERIALIZER` |
    `static byte[]` | `TOMBSTONE` |

  - ### Constructor Summary

    Constructors
    Constructor | Description
    --- | ---
    `DefaultStateEncoder​(Serializer<K> keySerializer, Serializer<V> valueSerializer)` |

  - ### Method Summary

    All Methods Instance Methods Concrete Methods
    Modifier and Type | Method | Description
    --- | --- | ---
    `K` | `decodeKey​(byte[] encodedKey)` | Decode key.
    `V` | `decodeValue​(byte[] encodedValue)` | Decode value.
    `byte[]` | `encodeKey​(K key)` | Encode key.
    `byte[]` | `encodeValue​(V value)` | Encode value.
    `Serializer<K>` | `getKeySerializer()` |
    `byte[]` | `getTombstoneValue()` | Get the tombstone value (deletion mark).
    `Serializer<V>` | `getValueSerializer()` |

    - ### Methods inherited from class java.lang.Object

      `clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait`

- - ### Field Detail

    - #### INTERNAL_VALUE_SERIALIZER

          public static final Serializer<Optional<byte[]>> INTERNAL_VALUE_SERIALIZER

    - #### TOMBSTONE

          public static final byte[] TOMBSTONE

  - ### Constructor Detail

    - #### DefaultStateEncoder

          public DefaultStateEncoder​(Serializer<K> keySerializer,
                                     Serializer<V> valueSerializer)

  - ### Method Detail

    - #### getKeySerializer

          public Serializer<K> getKeySerializer()

    - #### getValueSerializer

          public Serializer<V> getValueSerializer()

    - #### encodeKey

          public byte[] encodeKey​(K key)

      Description copied from interface: `StateEncoder`
      Encode key.
      Specified by:
        `encodeKey` in interface `StateEncoder<K,​V,​byte[],​byte[]>`
      Parameters:
        `key` - the value of key (K type)
      Returns:
        the encoded value of key (KENCODEDT type)

    - #### encodeValue

          public byte[] encodeValue​(V value)

      Description copied from interface: `StateEncoder`
      Encode value.
      Specified by:
        `encodeValue` in interface `StateEncoder<K,​V,​byte[],​byte[]>`
      Parameters:
        `value` - the value of value (V type)
      Returns:
        the encoded value of value (VENCODEDT type)

    - #### decodeKey

          public K decodeKey​(byte[] encodedKey)

      Description copied from interface: `StateEncoder`
      Decode key.
      Specified by:
        `decodeKey` in interface `StateEncoder<K,​V,​byte[],​byte[]>`
      Parameters:
        `encodedKey` - the value of key (KRAW type)
      Returns:
        the decoded value of key (K type)

    - #### decodeValue

          public V decodeValue​(byte[] encodedValue)

      Description copied from interface: `StateEncoder`
      Decode value.
      Specified by:
        `decodeValue` in interface `StateEncoder<K,​V,​byte[],​byte[]>`
      Parameters:
        `encodedValue` - the value of key (VENCODEDT type)
      Returns:
        the decoded value of key (V type)

    - #### getTombstoneValue

          public byte[] getTombstoneValue()

      Description copied from interface: `StateEncoder`
      Get the tombstone value (deletion mark).
      Specified by:
        `getTombstoneValue` in interface `StateEncoder<K,​V,​byte[],​byte[]>`
      Returns:
        the tomestone value (VENCODEDT type)