code: def batch_message(cls, batch, request_ids):
          '''Convert a request Batch to a message.'''
          assert isinstance(batch, Batch)
          if not cls.allow_batches:
              raise ProtocolError.invalid_request(
                  'protocol does not permit batches')
          id_iter = iter(request_ids)
          rm = cls.request_message
          nm = cls.notification_message
          parts = (rm(request, next(id_iter)) if isinstance(request, Request)
                   else nm(request) for request in batch)
          return cls.batch_message_from_parts(partsf batch_message(cls, batch, request_ids):
          '''Convert a request Batch to a message.'''
          assert isinstance(batch, Batch)
          if not cls.allow_batches:
              raise ProtocolError.invalid_request(
                  'protocol does not permit batches')
          id_iter = iter(request_ids)
          rm = cls.request_message
          nm = cls.notification_message
          parts = (rm(request, next(id_iter)) if isinstance(request, Request)
                   else nm(request) for request in batch)
          return cls.batch_message_from_parts(parts)
docs: Convert a request Batch to a message.