Skip to content

Commit 81a7540

Browse files
committed
MemoryRecords iterator; MemoryRecordsBuilder records() helper
1 parent f1543fd commit 81a7540

File tree

1 file changed

+14
-0
lines changed

1 file changed

+14
-0
lines changed

kafka/record/memory_records.py

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -109,6 +109,16 @@ def next_batch(self, _min_slice=MIN_SLICE,
109109
else:
110110
return DefaultRecordBatch(next_slice)
111111

112+
def __iter__(self):
113+
return self
114+
115+
def __next__(self):
116+
if not self.has_next():
117+
raise StopIteration
118+
return self.next_batch()
119+
120+
next = __next__
121+
112122

113123
class MemoryRecordsBuilder(object):
114124

@@ -186,6 +196,10 @@ def producer_id(self):
186196
def producer_epoch(self):
187197
return self._producer_epoch
188198

199+
def records(self):
200+
assert self._closed
201+
return MemoryRecords(self._buffer)
202+
189203
def close(self):
190204
# This method may be called multiple times on the same batch
191205
# i.e., on retries

0 commit comments

Comments
 (0)