code: def __iter__(self):
      if self._magic == 1:
          key_offset = self.KEY_OFFSET_V1
      else:
          key_offset = self.KEY_OFFSET_V0
      timestamp_type = self.timestamp_type
  
      if self.compression_type:
          # In case we will call iter again
          if not self._decompressed:
              self._buffer = memoryview(self._decompress(key_offset))
              self._decompressed = True
  
          # If relative offset is used, we need to decompress the entire
          # message first to compute the absolute offset.
          headers = self._read_all_headers()
          if self._magic > 0:
              msg_header, _ = headers[-1]
              absolute_base_offset = self._offset - msg_header[0]
          else:
              absolute_base_offset = -1
  
          for header, msg_pos in headers:
              offset, _, crc, _, attrs, timestamp = header
              # There should only ever be a single layer of compression
              assert not attrs & self.CODEC_MASK, (
                  "MessageSet at offset %d appears double-compressed. This "
                  "should not happen -- check your producers!"
                  % (offset,)
              )
  
              # When magic value is greater than 0, the timestamp
              # of a compressed message depends on the
              # timestamp type of the wrapper message:
              if timestamp_type == self.LOG_APPEND_TIME:
                  timestamp = self._timestamp
  
              if absolute_base_offset >= 0:
                  offset += absolute_base_offset
  
              key, value = self._read_key_value(msg_pos + key_offset)
              yield LegacyRecord(
                  offset, timestamp, timestamp_type, key, value, crc
              )
      else:
          key, value = self._read_key_value(key_offset)
          yield LegacyRecord(
              self._offset,
              self._timestamp,
              timestamp_type,
              key,
              value,
              self._crc,
          )
  
imports: import struct
  import time
  from kafka.record.abc import ABCRecord, ABCRecordBatch, ABCRecordBatchBuilder
  from kafka.record.util import calc_crc32
  from kafka.codec import gzip_encode, snappy_encode, lz4_encode, lz4_encode_old_kafka, gzip_decode, snappy_decode, lz4_decode, lz4_decode_old_kafka
  import kafka.codec
  from kafka.errors import CorruptRecordException, UnsupportedCodecError
label_desc: Use image node_id 9 for calling the LegacyRecordBatch obj's underlying member method code with example usage: obj.__iter__() without return types