@classmethod
    def pack(cls, val, str_cache=None, object_cache=None, traits_cache=None):
        if str_cache is None:
            str_cache = []

        if object_cache is None:
            object_cache = []

        if traits_cache is None:
            traits_cache = []

        chunks = []

        if isinstance(val, bool):
            if val is False:
                chunks.append(U8(AMF3_TYPE_FALSE))
            elif val is True:
                chunks.append(U8(AMF3_TYPE_TRUE))

        elif val is None:
            chunks.append(U8(AMF3_TYPE_NULL))

        elif isinstance(val, integer_types):
            if val < AMF3_MIN_INTEGER or val > AMF3_MAX_INTEGER:
                chunks.append(U8(AMF3_TYPE_DOUBLE))
                chunks.append(AMF3Double(val))
            else:
                chunks.append(U8(AMF3_TYPE_INTEGER))
                chunks.append(AMF3Integer(val))

        elif isinstance(val, float):
            chunks.append(U8(AMF3_TYPE_DOUBLE))
            chunks.append(AMF3Double(val))

        elif isinstance(val, (AMF3Array, list)):
            chunks.append(U8(AMF3_TYPE_ARRAY))
            chunks.append(AMF3ArrayPacker.pack(val, str_cache=str_cache,
                                              object_cache=object_cache,
                                              traits_cache=traits_cache))

        elif isinstance(val, string_types):
            chunks.append(U8(AMF3_TYPE_STRING))
            chunks.append(AMF3String.pack(val, cache=str_cache))

        elif isinstance(val, AMF3ObjectBase):
            chunks.append(U8(AMF3_TYPE_OBJECT))
            chunks.append(AMF3ObjectPacker.pack(val, str_cache=str_cache,
                                                object_cache=object_cache,
                                                traits_cache=traits_cache))

        elif isinstance(val, AMF3Date):
            chunks.append(U8(AMF3_TYPE_DATE))
            chunks.append(AMF3DatePacker.pack(val, cache=object_cache))

        else:
            raise ValueError("Unable to pack value of type {0}".format(type(val)))

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