def serialize(self):
        i = self.items()
        i.sort()
        L = []
        w = L.append
        for k, v in i:
            if type(k) == unicode:
                raise TypeError("Unicode key not allowed: %r" % k)
            if type(v) == unicode:
                raise TypeError(
                    "Unicode value for key %r not allowed: %r" % (k, v))
            if len(k) > MAX_KEY_LENGTH:
                raise TooLong(True, True, k, None)
            if len(v) > MAX_VALUE_LENGTH:
                raise TooLong(False, True, v, k)
            for kv in k, v:
                w(pack("!H", len(kv)))
                w(kv)
        w(pack("!H", 0))
        return ''.join(L)
Convert me into a wire-encoded string.
dataset/ETHPy150Open nlloyd/SubliminalCollaborator/libs/twisted/protocols/amp.py/AmpBox.serialize