Search in sources :

Example 21 with ObjectSerializationCache

use of org.apache.kafka.common.protocol.ObjectSerializationCache in project kafka by apache.

the class BytesApiMessageSerde method serialize.

public byte[] serialize(ApiMessageAndVersion messageAndVersion) {
    ObjectSerializationCache cache = new ObjectSerializationCache();
    int size = apiMessageSerde.recordSize(messageAndVersion, cache);
    ByteBufferAccessor writable = new ByteBufferAccessor(ByteBuffer.allocate(size));
    apiMessageSerde.write(messageAndVersion, cache, writable);
    return writable.buffer().array();
}
Also used : ObjectSerializationCache(org.apache.kafka.common.protocol.ObjectSerializationCache) ByteBufferAccessor(org.apache.kafka.common.protocol.ByteBufferAccessor)

Aggregations

ObjectSerializationCache (org.apache.kafka.common.protocol.ObjectSerializationCache)21 ByteBuffer (java.nio.ByteBuffer)13 ByteBufferAccessor (org.apache.kafka.common.protocol.ByteBufferAccessor)13 Test (org.junit.jupiter.api.Test)7 ApiMessageAndVersion (org.apache.kafka.server.common.ApiMessageAndVersion)3 FetchResponseData (org.apache.kafka.common.message.FetchResponseData)2 UpdateMetadataEndpoint (org.apache.kafka.common.message.UpdateMetadataRequestData.UpdateMetadataEndpoint)2 HashMap (java.util.HashMap)1 LinkedHashMap (java.util.LinkedHashMap)1 OptionalLong (java.util.OptionalLong)1 ExecutionException (java.util.concurrent.ExecutionException)1 TopicPartition (org.apache.kafka.common.TopicPartition)1 UnsupportedVersionException (org.apache.kafka.common.errors.UnsupportedVersionException)1 FetchRequestData (org.apache.kafka.common.message.FetchRequestData)1 LeaderChangeMessage (org.apache.kafka.common.message.LeaderChangeMessage)1 Voter (org.apache.kafka.common.message.LeaderChangeMessage.Voter)1 RequestHeaderData (org.apache.kafka.common.message.RequestHeaderData)1 RegisterBrokerRecord (org.apache.kafka.common.metadata.RegisterBrokerRecord)1 TopicRecord (org.apache.kafka.common.metadata.TopicRecord)1 Send (org.apache.kafka.common.network.Send)1