public byte[] serialize(String topic, ByteBuffer data) {
        if (data == null)
            return null;

        data.rewind();

        if (data.hasArray()) {
            byte[] arr = data.array();
            if (data.arrayOffset() == 0 && arr.length == data.remaining()) {
                return arr;
            }
        }

        byte[] ret = new byte[data.remaining()];
        data.get(ret, 0, ret.length);
        data.rewind();
        return ret;
    }
{@code ByteBufferSerializer} always {@link ByteBuffer#rewind() rewinds} the position of the input buffer to zero for
serialization. A manual rewind is not necessary.
<p>
Note: any existing buffer position is ignored.
<p>
The position is also rewound back to zero before {@link #serialize(String, ByteBuffer)}
returns.
clients/src/main/java/org/apache/kafka/common/serialization/ByteBufferSerializer.java