@Override
    public int writeTo(TransferableChannel channel, int position, int length) throws IOException {
        if (((long) position) + length > buffer.limit())
            throw new IllegalArgumentException("position+length should not be greater than buffer.limit(), position: "
                    + position + ", length: " + length + ", buffer.limit(): " + buffer.limit());

        return Utils.tryWriteTo(channel, position, length, buffer);
    }
A {@link Records} implementation backed by a ByteBuffer. This is used only for reading or
modifying in-place an existing buffer of record batches. To create a new buffer see {@link MemoryRecordsBuilder},
or one of the {@link #builder(ByteBuffer, byte, Compression, TimestampType, long)} variants.
clients/src/main/java/org/apache/kafka/common/record/MemoryRecords.java