code: def encode_message(cls, msg, stream_id, protocol_version, compressor, allow_beta_protocol_version):
          
          flags = 0
          body = io.BytesIO()
          if msg.custom_payload:
              if protocol_version < 4:
                  raise UnsupportedOperation("Custom key/value payloads can only be used with protocol version 4 or higher")
              flags |= CUSTOM_PAYLOAD_FLAG
              write_bytesmap(body, msg.custom_payload)
          msg.send_body(body, protocol_version)
          body = body.getvalue()
  
          if compressor and len(body) > 0:
              body = compressor(body)
              flags |= COMPRESSED_FLAG
  
          if msg.tracing:
              flags |= TRACING_FLAG
  
          if allow_beta_protocol_version:
              flags |= USE_BETA_FLAG
  
          buff = io.BytesIO()
          cls._write_header(buff, protocol_version, flags, stream_id, msg.opcode, len(body))
          buff.write(body)
  
          return buff.getvalue()
docs: Encodes a message using the specified frame parameters, and compressor
  
          :param msg: the message, typically of cassandra.protocol._MessageType, generated by the driver
          :param stream_id: protocol stream id for the frame header
          :param protocol_version: version for the frame header, and used encoding contents
          :param compressor: optional compression function to be used on the body