public static byte[] toArray(ByteBuffer buffer, int offset, int size) {
        byte[] dest = new byte[size];
        if (buffer.hasArray()) {
            System.arraycopy(buffer.array(), buffer.position() + buffer.arrayOffset() + offset, dest, 0, size);
        } else {
            int pos = buffer.position();
            buffer.position(pos + offset);
            buffer.get(dest);
            buffer.position(pos);
        }
        return dest;
    }
Read a byte array from the given offset and size in the buffer
@param buffer The buffer to read from
@param offset The offset relative to the current position of the buffer
@param size The number of bytes to read into the array
clients/src/main/java/org/apache/kafka/common/utils/Utils.java