<SYSTEM_TASK:>
Solve the following problem using Python, implementing the functions described below, one line at a time
<END_TASK>
<USER_TASK:>
Description:
 def to_binary_string(self):
 """Pack the notification to binary form and return it as string."""

        if self.priority not in self.PRIORITIES:
            raise NotificationInvalidPriorityError()

        try:
            token = binascii.unhexlify(self.token)
        except TypeError as error:
            raise NotificationTokenUnhexlifyError(error)

        try:
            payload = json.dumps(self.payload)
        except TypeError:
            raise NotificationPayloadNotSerializableError()

        fmt = ">BIBH{0}sBH{1}sBHIBHIBHB".format(len(token), len(payload))

        expire = (0 if self.expire == self.EXPIRE_IMMEDIATELY else
                  datetime_to_timestamp(self.expire))

        # |COMMAND|FRAME-LEN|{token}|{payload}|{id:4}|{expire:4}|{priority:1}
        # 5 items, each 3 bytes prefix, then each item length
        length = 3*5 + len(token) + len(payload) + 4 + 4 + 1
        message = struct.pack(fmt, self.COMMAND, length,
                              self.TOKEN, len(token), token,
                              self.PAYLOAD, len(payload), payload,
                              self.NOTIFICATION_ID, 4, self.iden,
                              self.EXPIRE, 4, expire,
                              self.PRIORITY, 1, self.priority)
        return message