@classmethod
    def size(cls, val, str_cache, object_cache, traits_cache):
        if val in object_cache:
            index = object_cache.index(val)
            return AMF3Integer.size(index << 1)
        else:
            object_cache.append(val)
            size = 0

            if isinstance(val, AMF3Array):
                dense_keys = val.dense_keys()
                length = len(dense_keys)
            else:
                length = len(val)
                dense_keys = list(range(length))

            header = length << 1 | 1
            size += AMF3Integer.size(header)

            if isinstance(val, AMF3Array):
                for key, value in val.items():
                    if key in dense_keys:
                        continue

                    size += AMF3String.size(key, cache=str_cache)
                    size += AMF3Value.size(value, str_cache=str_cache,
                                           object_cache=object_cache,
                                           traits_cache=traits_cache)

            size += U8.size

            for key in dense_keys:
                value = val[key]
                size += AMF3Value.size(value, str_cache=str_cache,
                                       object_cache=object_cache,
                                       traits_cache=traits_cache)

            return size
dataset/ETHPy150Open chrippa/livestreamer/src/livestreamer/packages/flashmedia/types.py/AMF3ArrayPacker.size/original