code: def _encode_message(cls, message):
          
          if message.magic == 0:
              msg = struct.pack('>BB', message.magic, message.attributes)
              msg += write_int_string(message.key)
              msg += write_int_string(message.value)
              crc = zlib.crc32(msg) & 0xffffffff  # Ensure unsigned
              msg = struct.pack('>I', crc) + msg
          else:
              raise ProtocolError("Unexpected magic number: %d" % message.magic)
          return msg
docs: Encode a single message.
  
          The magic number of a message is a format version number.  The only
          supported magic number right now is zero.  Format::
  
              Message => Crc MagicByte Attributes Key Value
                Crc => int32
                MagicByte => int8
                Attributes => int8
                Key => bytes
                Value => bytes