Serialize the token and return it as bytes.

def serialize(self):
        """Serialize the token and return it as bytes."""
        if type(self.value) == int:
            return "i{:X}s".format(self.value).encode('ascii')

        if type(self.value) == str:
            value = self.value.encode('utf-8')
            return "{:X}:".format(len(value)).encode('ascii') + value

        if type(self.value) == bytes:
            value = base64.standard_b64encode(self.value)
            return "u{:X}:".format(len(value)).encode('ascii') + value

        if type(self.value) == list:
            items = [LiveMessageToken(m).serialize() for m in self.value]
            return b'l' + b''.join(items) + b's'

        if type(self.value) == dict:
            items = []
            for key, value in self.value.items():
                items.append(LiveMessageToken(str(key)).serialize())
                items.append(LiveMessageToken(value).serialize())
            return b'h' + b''.join(items) + b's'

        raise RuntimeError("Unknown type %s" % type(self.value))