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();
    }
This class provides conversion of {@code ApiMessageAndVersion} to bytes and vice versa. This can be used as serialization protocol for any
metadata records derived of {@code ApiMessage}s. It internally uses {@link AbstractApiMessageSerde} for serialization/deserialization
mechanism.
<br><br>
Implementors need to extend this class and implement {@link #apiMessageFor(short)} method to return a respective
{@code ApiMessage} for the given {@code apiKey}. This is required to deserialize the bytes to build the respective
{@code ApiMessage} instance.
server-common/src/main/java/org/apache/kafka/server/common/serialization/BytesApiMessageSerde.java