def encode(self, transmission):
        """
        Encodes the data, creating a CWR structure from an instance from the
        domain model.

        :param entity: the instance to encode
        :return: a cwr string structure created from the received data
        """
        data = ''
        data += self._record_encode(transmission.header)
        for group in transmission.groups:
            data += self._record_encode(group.group_header)
            for transaction in group.transactions:
                for record in transaction:
                    data += self._record_encode(record)
            data += self._record_encode(group.group_trailer)
        data += self._record_encode(transmission.trailer)
        return data