public static object Deserialize_Class(BitStreamReader reader)
 {
     if (reader.ReadBit() == false)
     {
         return(null);
     }
     return(NetSerializer.Deserialize(reader));
 }
    public static bool GetMessageFromData(byte[] messageData, out object message)
    {
#if DEBUG
        if (s_dataLogChannel.Active)
        {
            Log.Info(s_dataLogChannel, $"[{nameof(NetMessageInterpreter)}] Receive Message byte[{messageData.Length}]");
            DebugLogUtility.LogByteArray(s_dataLogChannel, messageData);
        }
#endif
        try
        {
            message = NetSerializer.Deserialize(messageData);
            return(true);
        }
        catch (Exception e)
        {
            message = null;
            Log.Error($"[{nameof(NetMessageInterpreter)}] Failed to deserialize Message. {e.Message} - {e.StackTrace}");
            return(false);
        }
    }
        protected override IEnumerator ExecuteRoutine()
        {
            Log.Info("Start Sim Deserialization Process...");

            SerializedWorld serializedWorld = NetSerializer.Deserialize <SerializedWorld>(_serializedData);

            SerializeUtilityX.DeserializeWorld(serializedWorld.WorldData, _simulationWorld.EntityManager);

            Dictionary <uint, byte[]> blobAssetsMap = new Dictionary <uint, byte[]>(serializedWorld.BlobAssets.Length);

            for (int i = 0; i < serializedWorld.BlobAssets.Length; i++)
            {
                blobAssetsMap.Add(serializedWorld.BlobAssets[i].Id, serializedWorld.BlobAssets[i].Data);
            }

            Dictionary <ComponentType, Type> compToManaged = new Dictionary <ComponentType, Type>();
            Dictionary <ComponentType, DynamicComponentTypeHandle> compToHandle = new Dictionary <ComponentType, DynamicComponentTypeHandle>();
            NativeArray <ArchetypeChunk> chunks = _simulationWorld.EntityManager.GetAllChunks(Allocator.TempJob);

            foreach (var item in BlobAssetDataDistributors.Values)
            {
                item.BeginDistribute(_simulationWorld);
            }

            // iterate over all chunks
            for (int i = 0; i < chunks.Length; i++)
            {
                ArchetypeChunk chunk = chunks[i];

                // iterate over all components in chunk
                foreach (ComponentType componentType in chunk.Archetype.GetComponentTypes())
                {
                    // get managed type
                    if (!compToManaged.TryGetValue(componentType, out Type managedType))
                    {
                        managedType = componentType.GetManagedType();
                        compToManaged[componentType] = managedType;
                    }

                    // if collector exists for given component, invoke it
                    if (BlobAssetDataDistributors.TryGetValue(managedType, out IPtrObjectDistributor collector))
                    {
                        // get componentTypeHandle (necessary for chunk data access)
                        if (!compToHandle.TryGetValue(componentType, out DynamicComponentTypeHandle typeHandle))
                        {
                            typeHandle = _simulationWorld.EntityManager.GetDynamicComponentTypeHandle(componentType);
                            compToHandle[componentType] = typeHandle;
                        }

                        // invoke!
                        collector.Distribute(typeHandle, chunk, blobAssetsMap);
                    }
                }
            }
            chunks.Dispose();

            foreach (var item in BlobAssetDataDistributors.Values)
            {
                item.EndDistribute();
            }

            Log.Info("Sim Deserialization Complete!");
            TerminateWithSuccess();

            yield break;
        }
 public T Deserialize <T>(byte[] serialized)
 {
     return(Serializer.Deserialize <T>(serialized));
 }