code: def _maybe_compress(self):
      if self._compression_type:
          self._assert_has_codec(self._compression_type)
          data = bytes(self._buffer)
          if self._compression_type == self.CODEC_GZIP:
              compressed = gzip_encode(data)
          elif self._compression_type == self.CODEC_SNAPPY:
              compressed = snappy_encode(data)
          elif self._compression_type == self.CODEC_LZ4:
              if self._magic == 0:
                  compressed = lz4_encode_old_kafka(data)
              else:
                  compressed = lz4_encode(data)
          size = self.size_in_bytes(
              0, timestamp=0, key=None, value=compressed
          )
          # We will try to reuse the same buffer if we have enough space
          if size > len(self._buffer):
              self._buffer = bytearray(size)
          else:
              del self._buffer[size:]
          self._encode_msg(
              start_pos=0,
              offset=0,
              timestamp=0,
              key=None,
              value=compressed,
              attributes=self._compression_type,
          )
          return True
      return False
  
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 4 for calling the LegacyRecordBatchBuilder obj's underlying member method code with example usage: obj._maybe_compress() and returns: False, True