Ejemplo n.º 1
0
        public void Deserialize(byte[] buffer, ref int offset, ref Type value)
        {
            int mode = SerializerBinary.ReadUInt32Bias(buffer, ref offset, Bias);

            // Null
            if (mode == Null)
            {
                value = null;
                return;
            }

            var typeCache = _serializer.InstanceData.TypeCache;

            // Existing
            if (mode >= 0)
            {
                var id = mode;
                value = typeCache.GetExistingObject <Type>(id);
                return;
            }


            bool isComposite = mode == NewComposite;

            if (isComposite)             // composite aka "closed generic"
            {
                // Read main type
                var compositeProxy = typeCache.CreateDeserializationProxy <Type>();

                Type baseType = value;
                Deserialize(buffer, ref offset, ref baseType);


                // Read count
                var    argCount    = SerializerBinary.ReadByte(buffer, ref offset);
                Type[] genericArgs = new Type[argCount];
                for (int i = 0; i < argCount; i++)
                {
                    var genericArgProxy = typeCache.CreateDeserializationProxy <Type>();

                    Deserialize(buffer, ref offset, ref genericArgProxy.Value);

                    genericArgs[i] = genericArgProxy.Value;
                }

                value = _typeBinder.GetTypeFromBaseAndAgruments(baseType.FullName, genericArgs);
                compositeProxy.Value = value;                 // make it available for future deserializations
            }
            else
            {
                var proxy = typeCache.CreateDeserializationProxy <Type>();

                string baseTypeName = SerializerBinary.ReadString(buffer, ref offset);
                value = _typeBinder.GetTypeFromBase(baseTypeName);

                proxy.Value = value;
            }
        }
Ejemplo n.º 2
0
        public void Deserialize(byte[] buffer, ref int offset, ref Type value)
        {
            int mode = SerializerBinary.ReadUInt32Bias(buffer, ref offset, Bias);

            // Null
            if (mode == Null)
            {
                value = null;
                return;
            }

            var typeCache = _serializer.InstanceData.TypeCache;

            // Existing
            if (mode >= 0)
            {
                var id = mode;
                value = typeCache.GetExistingObject <Type>(id);
                return;
            }


            bool isComposite = mode == NewGeneric;

            if (isComposite)             // composite aka "closed generic"
            {
                // Read base type first (example: Dictionary<T1, T2>)
                Type baseType = value;
                Deserialize(buffer, ref offset, ref baseType);


                // Read count (example: 2)
                var    argCount    = SerializerBinary.ReadByte(buffer, ref offset);
                Type[] genericArgs = new Type[argCount];

                // Read all inner type definitions (in our example: 'string' and 'object)
                for (int i = 0; i < argCount; i++)
                {
                    Deserialize(buffer, ref offset, ref genericArgs[i]);
                }


                // Read construct full composite (example: Dictionary<string, object>)
                var compositeProxy = typeCache.CreateDeserializationProxy <Type>();

                value = _typeBinder.GetTypeFromBaseAndAgruments(baseType.FullName, genericArgs);
                compositeProxy.Value = value;                 // make it available for future deserializations
            }
            else
            {
                var proxy = typeCache.CreateDeserializationProxy <Type>();

                string baseTypeName = SerializerBinary.ReadString(buffer, ref offset);
                value = _typeBinder.GetTypeFromBase(baseTypeName);

                proxy.Value = value;
            }

            // todo: what to do when the type is not written because it is the same already?
            // a) force writing the type when embedding version info
            // b) just write schema, assuming the type

            if (_serializer.Config.VersionTolerance == VersionTolerance.AutomaticEmbedded)
            {
                if (!CerasSerializer.FrameworkAssemblies.Contains(value.Assembly))
                {
                    _serializer.ReadSchemaForType(buffer, ref offset, value);
                }
            }
        }
Ejemplo n.º 3
0
        public void Deserialize(byte[] buffer, ref int offset, ref Type type)
        {
            int mode = SerializerBinary.ReadUInt32Bias(buffer, ref offset, Bias);

            // Null
            if (mode == Null)
            {
                type = null;
                return;
            }

            var typeCache = _serializer.InstanceData.TypeCache;

            // Existing
            if (mode >= 0)
            {
                var id = mode;
                type = typeCache.GetExistingObject(id);
                return;
            }


            bool isComposite = mode == NewGeneric;

            if (isComposite)             // composite aka "closed generic"
            {
                // Read base type first (example: Dictionary<T1, T2>)
                Type baseType = type;
                Deserialize(buffer, ref offset, ref baseType);


                // Read count (example: 2)
                var    argCount    = SerializerBinary.ReadByte(buffer, ref offset);
                Type[] genericArgs = new Type[argCount];

                // Read all inner type definitions (in our example: 'string' and 'object)
                for (int i = 0; i < argCount; i++)
                {
                    Deserialize(buffer, ref offset, ref genericArgs[i]);
                }


                // Read construct full composite (example: Dictionary<string, object>)
                var compositeProxy = typeCache.CreateDeserializationProxy();

                type = _typeBinder.GetTypeFromBaseAndAgruments(baseType.FullName, genericArgs);
                compositeProxy.Type = type;                 // make it available for future deserializations

                if (_isSealed)
                {
                    ThrowSealed(type, false);
                }
            }
            else
            {
                var proxy = typeCache.CreateDeserializationProxy();

                string baseTypeName = SerializerBinary.ReadString(buffer, ref offset);
                type = _typeBinder.GetTypeFromBase(baseTypeName);

                proxy.Type = type;

                if (_isSealed)
                {
                    ThrowSealed(type, false);
                }
            }
        }