Exemplo n.º 1
0
        public static object DeserializeFromStream(Stream stream)
        {
            int dataType = stream.ReadByte();

            if (dataType < 0)
            {
                return(null);
            }

            object o = null;
            byte   useCompression = 0;
            Stream gzip           = null;

            if (dataType == 'c' || dataType == 'a')
            {
                useCompression = (byte)stream.ReadByte();
            }

            switch (useCompression)
            {
            case 0: gzip = stream; break;

            case 1: gzip = new GZipStream(stream, CompressionMode.Decompress); break;

            case 2: gzip = new DeflateStream(stream, CompressionMode.Decompress); break;
                //case 3: gzip = new SevenZip.LzmaDecodeStream(stream); break;
            }
            using (gzip)
            {
                if (dataType == 'a')
#if !SAFE_COPY
                { lock (AltSerialization.Locker)
#endif
                    o = AltSerialization.Deserialize(gzip); }
                else
                {
                    var bi = new BinaryFormatter();
                    o = bi.Deserialize(gzip);
                }
            }
            return(o);
        }
Exemplo n.º 2
0
        void DeserializeValueFields(object value, AltSerialization serialization, IntPtr ptr)
        {
            if (BaseType != null)
            {
                BaseType.DeserializeValueFields(value, serialization, ptr);
            }

#if SAFE_COPY
            foreach (var field in ValueFields)
            {
                field.SetValue(value, serialization.Deserialize(field.FieldType.IsSealed ? field.FieldType : null));
            }
#else
            if (valueFieldsSize > 0)
            {
                //var data = new byte[valueFieldsSize];
                serialization.Reader.Read(data, 0, valueFieldsSize);
                //lock (locker)
                Marshal.Copy(data, 0, ptr + valueFieldsStart, valueFieldsSize);
            }
#endif
        }