Beispiel #1
0
        public object Deserialize(Stream source, object value, Type type, int length, SerializationContext context)
        {
            bool noAutoCreate = this.PrepareDeserialize(value, ref type);

            using (ProtoReader reader = new ProtoReader(source, this, context, length))
            {
                if (value != null)
                {
                    reader.SetRootObject(value);
                }
                object obj2 = this.DeserializeCore(reader, type, value, noAutoCreate);
                reader.CheckFullyConsumed();
                return(obj2);
            }
        }
        public object Deserialize(ProtoReader source, object value, Type type)
        {
            if (source == null)
            {
                throw new ArgumentNullException("source");
            }
            bool noAutoCreate = PrepareDeserialize(value, ref type);

            if (value != null)
            {
                source.SetRootObject(value);
            }
            object result = DeserializeCore(source, type, value, noAutoCreate);

            source.CheckFullyConsumed();
            return(result);
        }
        public object Deserialize(Stream source, object value, Type type, int length, SerializationContext context)
        {
            bool        noAutoCreate = PrepareDeserialize(value, ref type);
            ProtoReader protoReader  = null;

            try
            {
                protoReader = ProtoReader.Create(source, this, context, length);
                if (value != null)
                {
                    protoReader.SetRootObject(value);
                }
                object result = DeserializeCore(protoReader, type, value, noAutoCreate);
                protoReader.CheckFullyConsumed();
                return(result);
            }
            finally
            {
                ProtoReader.Recycle(protoReader);
            }
        }
Beispiel #4
0
        public object Deserialize(Stream source, object value, Type type, SerializationContext context)
        {
            bool        autoCreate = this.PrepareDeserialize(value, ref type);
            ProtoReader reader     = null;
            object      result;

            try
            {
                reader = ProtoReader.Create(source, this, context, -1);
                if (value != null)
                {
                    reader.SetRootObject(value);
                }
                object obj = this.DeserializeCore(reader, type, value, autoCreate);
                reader.CheckFullyConsumed();
                result = obj;
            }
            finally
            {
                ProtoReader.Recycle(reader);
            }
            return(result);
        }
Beispiel #5
0
        public static T Deserialize(Stream stream, T obj)
        {
            if (_invoke == null)
            {
                return(_default(stream));
            }

            obj = ProtoSerializeHelper <T> .CreateInstance(obj);

            ProtoReader source = null;

            try
            {
                source = ProtoReader.Create(stream, RuntimeTypeModel.Default, null, ProtoReader.TO_EOF);
                source.SetRootObject(obj);
                obj = _invoke(source, obj);
                source.CheckFullyConsumed();
                return(obj);
            }
            finally
            {
                ProtoReader.Recycle(source);
            }
        }