CloseableIterator<Record> iterator(BufferSupplier bufferSupplier) {
        if (isCompressed())
            return new DeepRecordsIterator(this, false, Integer.MAX_VALUE, bufferSupplier);

        return new CloseableIterator<Record>() {
            private boolean hasNext = true;

            @Override
            public void close() {}

            @Override
            public boolean hasNext() {
                return hasNext;
            }

            @Override
            public Record next() {
                if (!hasNext)
                    throw new NoSuchElementException();
                hasNext = false;
                return AbstractLegacyRecordBatch.this;
            }

            @Override
            public void remove() {
                throw new UnsupportedOperationException();
            }
        };
    }
Get an iterator for the nested entries contained within this batch. Note that
if the batch is not compressed, then this method will return an iterator over the
shallow record only (i.e. this object).
@return An iterator over the records contained within this batch
clients/src/main/java/org/apache/kafka/common/record/AbstractLegacyRecordBatch.java