docstr: Compressed messages should pass in bytes_to_read (via message size)
  otherwise, we decode from data as Int32
docstr_tok: ["Compressed","messages","should","pass","in","bytes_to_read","(","via","message","size",")","otherwise",",","we","decode","from","data","as","Int32"]
code: def decode(cls, data, bytes_to_read=None):
      """Compressed messages should pass in bytes_to_read (via message size)
      otherwise, we decode from data as Int32
      """
      if isinstance(data, bytes):
          data = io.BytesIO(data)
      if bytes_to_read is None:
          bytes_to_read = Int32.decode(data)
  
      # if FetchRequest max_bytes is smaller than the available message set
      # the server returns partial data for the final message
      # So create an internal buffer to avoid over-reading
      raw = io.BytesIO(data.read(bytes_to_read))
  
      items = []
      while bytes_to_read:
          try:
              offset = Int64.decode(raw)
              msg_bytes = Bytes.decode(raw)
              bytes_to_read -= 8 + 4 + len(msg_bytes)
              items.append(
                  (offset, len(msg_bytes), Message.decode(msg_bytes))
              )
          except ValueError:
              # PartialMessage to signal that max_bytes may be too small
              items.append((None, None, PartialMessage()))
              break
      return items
  
imports: from __future__ import absolute_import
  import io
  import time
  from kafka.codec import has_gzip, has_snappy, has_lz4, has_zstd, gzip_decode, snappy_decode, zstd_decode, lz4_decode, lz4_decode_old_kafka
  from kafka.protocol.frame import KafkaBytes
  from kafka.protocol.struct import Struct
  from kafka.protocol.types import Int8, Int32, Int64, Bytes, Schema, AbstractType
  from kafka.util import crc32, WeakMethod
label_desc: Use image node_id 2 for calling the MessageSet obj's underlying member method code with example usage: obj.decode(cls, data, bytes_to_read) and returns: items