private void flushPendingBuffer() {
        int latestPosition = buffer.position();
        buffer.reset();

        if (latestPosition > buffer.position()) {
            buffer.limit(latestPosition);
            addBuffer(buffer.slice());

            buffer.position(latestPosition);
            buffer.limit(buffer.capacity());
            buffer.mark();
        }
    }
Write a record set. The underlying record data will be retained
in the result of {@link #build()}. See {@link BaseRecords#toSend()}.

@param records the records to write
clients/src/main/java/org/apache/kafka/common/protocol/SendBuilder.java