code: def encode(cls, items, prepend_size=True):
      # RecordAccumulator encodes messagesets internally
      if isinstance(items, (io.BytesIO, KafkaBytes)):
          size = Int32.decode(items)
          if prepend_size:
              # rewind and return all the bytes
              items.seek(items.tell() - 4)
              size += 4
          return items.read(size)
  
      encoded_values = []
      for offset, message in items:
          encoded_values.append(Int64.encode(offset))
          encoded_values.append(Bytes.encode(message))
      encoded = b"".join(encoded_values)
      if prepend_size:
          return Bytes.encode(encoded)
      else:
          return encoded
  
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 1 for calling the MessageSet obj's underlying member method code with example usage: obj.encode(cls, items, prepend_size) and returns: items, Bytes, encoded