Class KeyValue<K,V>

java.lang.Object
org.apache.pulsar.common.schema.KeyValue<K,V>

@Public @Stable public class KeyValue<K,V> extends Object
A simple KeyValue class.
  • Constructor Details

    • KeyValue

      public KeyValue(K key, V value)
  • Method Details

    • getKey

      public K getKey()
    • getValue

      public V getValue()
    • hashCode

      public int hashCode()
      Overrides:
      hashCode in class Object
    • equals

      public boolean equals(Object obj)
      Overrides:
      equals in class Object
    • toString

      public String toString()
      Overrides:
      toString in class Object
    • encode

      public static <K, V> byte[] encode(K key, Schema<K> keyWriter, V value, Schema<V> valueWriter)
      Encode a key and value pair into a bytes array.
      Parameters:
      key - key object to encode
      keyWriter - a writer to encode key object
      value - value object to encode
      valueWriter - a writer to encode value object
      Returns:
      the encoded bytes array
    • decode

      public static <K, V> KeyValue<K,V> decode(byte[] data, KeyValue.KeyValueDecoder<K,V> decoder)
      Decode the value into a key/value pair.
      Parameters:
      data - the encoded bytes
      decoder - the decoder to decode encoded key/value bytes
      Returns:
      the decoded key/value pair