@classmethod
    def pack(cls, val, cache):
        data = String.pack(val, "utf8", "ignore")
        size = len(data)

        if size == 0:
            return U8(AMF3_EMPTY_STRING)
        elif val in cache:
            index = cache.index(val)
            return AMF3Integer(index << 1)
        else:
            cache.append(val)

            chunks = []
            chunks.append(AMF3Integer(size << 1 | 1))
            chunks.append(data)

            return b"".join(chunks)
dataset/ETHPy150Open chrippa/livestreamer/src/livestreamer/packages/flashmedia/types.py/AMF3String.pack/original