private JobHandle SchedulePersistJobs(JobHandle inputDeps, PersistentDataContainer dataContainer, ComponentTypeHandle <PersistenceState> persistenceStateTypeHandle)
        {
            var returnJobHandle = inputDeps;

            for (int persistenceArchetypeIndex = 0; persistenceArchetypeIndex < dataContainer.DataLayoutCount; persistenceArchetypeIndex++)
            {
                PersistencyArchetypeDataLayout dataLayout = dataContainer.GetDataLayoutAtIndex(persistenceArchetypeIndex);
                ref BlobArray <PersistencyArchetypeDataLayout.TypeInfo> typeInfoArray = ref dataLayout.PersistedTypeInfoArrayRef.Value;

                PersistencyContainerTag containerTag = new PersistencyContainerTag {
                    DataIdentifier = dataContainer.DataIdentifier
                };
                PersistableTypeCombinationHash persistableTypeCombinationHash = new PersistableTypeCombinationHash {
                    Value = dataLayout.PersistableTypeHandleCombinationHash
                };

                for (int typeInfoIndex = 0; typeInfoIndex < typeInfoArray.Length; typeInfoIndex++)
                {
                    // type info
                    PersistencyArchetypeDataLayout.TypeInfo typeInfo = typeInfoArray[typeInfoIndex];
                    ComponentType runtimeType = ComponentType.ReadOnly(PersistencySettings.GetTypeIndex(typeInfo.PersistableTypeHandle));
                    int           stride      = typeInfo.ElementSize * typeInfo.MaxElements + PersistenceMetaData.SizeOfStruct;
                    int           byteSize    = dataLayout.Amount * stride;

                    // query
                    var query = PersistableEntitiesQuery;
                    query.SetSharedComponentFilter(containerTag, persistableTypeCombinationHash);

                    JobHandle jobHandle;
                    if (typeInfo.IsBuffer)
                    {
                        jobHandle = new CopyBufferElementsToByteArray
                        {
                            BufferTypeHandle     = GetDynamicComponentTypeHandle(runtimeType),
                            MaxElements          = typeInfo.MaxElements,
                            PersistenceStateType = persistenceStateTypeHandle,
                            RawContainerData     = dataContainer.GetRawData(),
                            SubArrayOffset       = dataLayout.Offset + typeInfo.Offset,
                            SubArrayByteSize     = byteSize,
                            ElementSize          = typeInfo.ElementSize
                        }.Schedule(query, inputDeps);
                    }
                    else
                    {
                        jobHandle = new CopyComponentDataToByteArray()
                        {
                            ComponentTypeHandle  = GetDynamicComponentTypeHandle(runtimeType),
                            TypeSize             = typeInfo.ElementSize,
                            PersistenceStateType = persistenceStateTypeHandle,
                            RawContainerData     = dataContainer.GetRawData(),
                            SubArrayOffset       = dataLayout.Offset + typeInfo.Offset,
                            SubArrayByteSize     = byteSize
                        }.Schedule(query, inputDeps);
                    }

                    query.ResetFilter();
                    returnJobHandle = JobHandle.CombineDependencies(returnJobHandle, jobHandle);
                }
            }
        public void ReadContainerData(PersistentDataContainer container)
        {
            string path = GetResourcePath(container.DataIdentifier);

            Debug.Assert(File.Exists(path));

            using (var fileStream = new FileStream(path, FileMode.Open))
            {
                int length = (int)fileStream.Length;
                // Read Data
                byte[] dataByteArray = new byte[length];
                fileStream.Read(dataByteArray, 0, length);
                container.GetRawData().CopyFrom(dataByteArray);
            }
        }
        public void WriteContainerData(PersistentDataContainer container)
        {
            string path       = GetResourcePath(container.DataIdentifier);
            string folderPath = Path.GetDirectoryName(path);

            if (!Directory.Exists(folderPath))
            {
                Directory.CreateDirectory(folderPath);
            }

            using (var fileStream = new FileStream(path, FileMode.Create))
            {
                var dataArray = container.GetRawData().ToArray();
                fileStream.Write(dataArray, 0, dataArray.Length);
            }
        }