Package org.apache.pulsar.common.schema
Class KeyValue<K,V>
java.lang.Object
org.apache.pulsar.common.schema.KeyValue<K,V>
A simple KeyValue class.
-
Nested Class Summary
Nested ClassesModifier and TypeClassDescriptionstatic interfaceDecoder to decode key/value bytes. -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionstatic <K,V> KeyValue <K, V> decode(byte[] data, KeyValue.KeyValueDecoder<K, V> decoder) Decode the value into a key/value pair.static <K,V> EncodeData static <K,V> byte[] Encode a key and value pair into a bytes array.booleanstatic byte[]generateKVSchemaId(byte[] keySchemaId, byte[] valueSchemaId) Generate a combined schema id for key/value schema.getKey()static KeyValue<byte[], byte[]> getSchemaId(byte[] schemaId) getValue()inthashCode()toString()
-
Constructor Details
-
KeyValue
-
-
Method Details
-
getKey
-
getValue
-
hashCode
public int hashCode() -
equals
-
toString
-
encode
Encode a key and value pair into a bytes array.- Parameters:
key- key object to encodekeyWriter- a writer to encode key objectvalue- value object to encodevalueWriter- a writer to encode value object- Returns:
- the encoded bytes array
-
encode
public static <K,V> EncodeData encode(String topic, K key, Schema<K> keyWriter, V value, Schema<V> valueWriter) -
generateKVSchemaId
public static byte[] generateKVSchemaId(byte[] keySchemaId, byte[] valueSchemaId) Generate a combined schema id for key/value schema. The format is: schemaId = schemaKeyLength + keySchemaIdBytes + schemaValueLength + valueSchemaIdBytes where schemaKeyLength and schemaValueLength are 4 bytes integer. If keySchemaIdBytes or valueSchemaIdBytes is null, the length will be 0. So the total length of schemaId is: 4 + keySchemaIdBytes.length + 4 + valueSchemaIdBytes.length- Parameters:
keySchemaId- the schema id of key schemavalueSchemaId- the schema id of value schema
-
getSchemaId
-
decode
Decode the value into a key/value pair.- Parameters:
data- the encoded bytesdecoder- the decoder to decode encoded key/value bytes- Returns:
- the decoded key/value pair
-