示例#1
0
        public override T Deserialize <T>(Stream stream)
        {
            var tools = _tools;

            if (tools is null)
            {
                tools  = new SerTools();
                _tools = tools;
            }
            if (Compressor is null)
            {
                if (typeof(T) == typeof(GenericObject))
                {
                    return((T)tools.Deserializer.GenericObjectDeserialize(stream));
                }
                return((T)tools.Deserializer.Deserialize(stream));
            }
            tools.ComStream.Reset();
            Compressor.Decompress(stream, tools.ComStream);
            tools.ComStream.Position = 0;
            if (typeof(T) == typeof(GenericObject))
            {
                return((T)tools.Deserializer.GenericObjectDeserialize(tools.ComStream));
            }
            return((T)tools.Deserializer.Deserialize(tools.ComStream));
        }
示例#2
0
        protected override void OnSerialize(Stream stream, object item, Type itemType)
        {
            var tools = _tools;

            if (tools is null)
            {
                tools  = new SerTools();
                _tools = tools;
            }
            tools.Serializer.Serialize(stream, item, itemType);
        }
示例#3
0
        protected override object OnDeserialize(Stream stream, Type itemType)
        {
            var tools = _tools;

            if (tools is null)
            {
                tools  = new SerTools();
                _tools = tools;
            }
            if (itemType == typeof(GenericObject))
            {
                return(tools.Deserializer.GenericObjectDeserialize(stream));
            }
            return(tools.Deserializer.Deserialize(stream));
        }
示例#4
0
        public override void Serialize <T>(T item, Stream stream)
        {
            var tools = _tools;

            if (tools is null)
            {
                tools  = new SerTools();
                _tools = tools;
            }
            if (Compressor is null)
            {
                tools.Serializer.Serialize(stream, item);
                return;
            }
            tools.SerStream.Reset();
            tools.Serializer.Serialize(tools.SerStream, item);
            tools.SerStream.Position = 0;
            Compressor.Compress(tools.SerStream, stream);
        }
示例#5
0
        public override T Deserialize <T>(MultiArray <byte> value)
        {
            var tools = _tools;

            if (tools is null)
            {
                tools  = new SerTools();
                _tools = tools;
            }
            if (Compressor is null)
            {
                using (var stream = value.AsReadOnlyStream())
                    return((T)tools.Deserializer.Deserialize(stream));
            }
            tools.ComStream.Reset();
            using (var stream = value.AsReadOnlyStream())
                Compressor.Decompress(stream, tools.ComStream);
            tools.ComStream.Position = 0;
            return((T)tools.Deserializer.Deserialize(tools.ComStream));
        }
示例#6
0
        public override MultiArray <byte> Serialize <T>(T item)
        {
            var tools = _tools;

            if (tools is null)
            {
                tools  = new SerTools();
                _tools = tools;
            }
            else
            {
                tools.SerStream.Reset();
            }
            if (Compressor is null)
            {
                tools.Serializer.Serialize(tools.SerStream, item);
                return(tools.SerStream.GetMultiArray());
            }
            tools.ComStream.Reset();
            tools.Serializer.Serialize(tools.SerStream, item);
            tools.SerStream.Position = 0;
            Compressor.Compress(tools.SerStream, tools.ComStream);
            return(tools.ComStream.GetMultiArray());
        }