public abstract class AbstractApiMessageSerde extends Object implements RecordSerde<ApiMessageAndVersion>
RecordSerde with ApiMessageAndVersion but implementors need to implement
apiMessageFor(short) to return a ApiMessage instance for the given apiKey.
This can be used as the underlying serialization mechanism for records defined with ApiMessages.
Serialization format for the given ApiMessageAndVersion is below:
[data_frame_version header message]
header => [api_key version]
data_frame_version : This is the header version, current value is 0. Header includes both api_key and version.
api_key : apiKey of ApiMessageAndVersion object.
version : version of ApiMessageAndVersion object.
message : serialized message of ApiMessageAndVersion object.
| Constructor and Description |
|---|
AbstractApiMessageSerde() |
| Modifier and Type | Method and Description |
|---|---|
abstract org.apache.kafka.common.protocol.ApiMessage |
apiMessageFor(short apiKey)
Return
ApiMessage instance for the given apiKey. |
ApiMessageAndVersion |
read(org.apache.kafka.common.protocol.Readable input,
int size)
Read a record from a
Readable input. |
int |
recordSize(ApiMessageAndVersion data,
org.apache.kafka.common.protocol.ObjectSerializationCache serializationCache)
Get the size of a record.
|
void |
write(ApiMessageAndVersion data,
org.apache.kafka.common.protocol.ObjectSerializationCache serializationCache,
org.apache.kafka.common.protocol.Writable out)
Write the record to the output stream.
|
public int recordSize(ApiMessageAndVersion data, org.apache.kafka.common.protocol.ObjectSerializationCache serializationCache)
RecordSerdeRecordSerde.write(Object, ObjectSerializationCache, Writable).recordSize in interface RecordSerde<ApiMessageAndVersion>data - the record that will be serializedserializationCache - serialization cachepublic void write(ApiMessageAndVersion data, org.apache.kafka.common.protocol.ObjectSerializationCache serializationCache, org.apache.kafka.common.protocol.Writable out)
RecordSerdeRecordSerde.recordSize(Object, ObjectSerializationCache).
The same ObjectSerializationCache instance must be used in both calls.write in interface RecordSerde<ApiMessageAndVersion>data - the record to serialize and writeserializationCache - serialization cacheout - the output stream to write the record topublic ApiMessageAndVersion read(org.apache.kafka.common.protocol.Readable input, int size)
RecordSerdeReadable input.read in interface RecordSerde<ApiMessageAndVersion>input - the input stream to deserializesize - the size of the record in bytespublic abstract org.apache.kafka.common.protocol.ApiMessage apiMessageFor(short apiKey)
ApiMessage instance for the given apiKey. This is used while deserializing the bytes
payload into the respective ApiMessage in read(Readable, int) method.apiKey - apiKey for which a ApiMessage to be created.