コード例 #1
0
        public void InnerDeserializeObject(ref object instance, BarfDeserializationArgs readArgs)
        {
            var typedInstance = instance == null ? default(T) : (T)instance;

            InnerDeserialize(ref typedInstance, readArgs);
            instance = typedInstance;
        }
コード例 #2
0
ファイル: BarfFormatter.cs プロジェクト: wilson0x4d/DataRelay
        /// <summary>
        /// Deserializes an object of the specified type from <paramref name="input"/>.
        /// </summary>
        /// <typeparam name="T">The type of object to deserialize.</typeparam>
        /// <param name="input">The stream to read from.</param>
        /// <returns>The deserialized object. <see langword="null"/> values are possible
        /// if <see langword="null"/> was originally serialized into the stream.</returns>
        /// <exception cref="ArgumentNullException">
        ///		<para><paramref name="input"/> is <see langword="null"/>.</para>
        /// </exception>
        /// <exception cref="ArgumentException">
        ///		<para><paramref name="input.CanSeek"/> is <see langword="false"/>.</para>
        /// </exception>
        public static T Deserialize <T>(Stream input)
        {
            ArgumentAssert.IsNotNull(input, "input");
            if (!input.CanSeek)
            {
                throw new ArgumentException("input.CanSeek must be true", "input");
            }

            var serializer = BarfSerializers.Get <T>(PartFlags.None);
            var args       = new BarfDeserializationArgs(SerializerFactory.GetReader(input));

            return(serializer.Deserialize(args));
        }
コード例 #3
0
        public T Deserialize(BarfDeserializationArgs readArgs)
        {
            var value = readArgs.Reader.ReadByte();

            if (value == SerializerHeaders.Barf)
            {
                var result = default(T);
                InnerDeserialize(ref result, readArgs);
                return(result);
            }
            else
            {
                readArgs.Reader.BaseStream.Seek(-1L, SeekOrigin.Current);

                object result = CreateEmpty();
                _typeSerializer.Value.Deserialize(ref result, new TypeSerializationArgs
                {
                    Reader = readArgs.Reader,
                    Flags  = SerializerFlags.Default
                });
                return((T)result);
            }
        }
コード例 #4
0
 public static void ReadPart <T>(ref T instance, BarfDeserializationArgs args, PartFlags flags)
 {
     if (flags.IsSet(PartFlags.Dynamic))
     {
         var index = args.Reader.ReadVarInt32();
         if (index < 0)
         {
             instance = default(T);
         }
         else
         {
             var    type       = args.TypeTable.GetType(index);
             var    serializer = BarfSerializers.Get(type, flags & ~PartFlags.Dynamic);
             object obj        = instance;
             serializer.InnerDeserializeObject(ref obj, args);
             instance = (T)obj;
         }
     }
     else
     {
         BarfSerializers.Get <T>(flags).InnerDeserialize(ref instance, args);
     }
 }
コード例 #5
0
 public object DeserializeObject(BarfDeserializationArgs readArgs)
 {
     return(Deserialize(readArgs));
 }
コード例 #6
0
 protected internal abstract void InnerDeserialize(ref T instance, BarfDeserializationArgs readArgs);
コード例 #7
0
 protected internal override void InnerDeserialize(ref T instance, BarfDeserializationArgs readArgs)
 {
     _deserializeMethod.Value(ref instance, readArgs);
 }
コード例 #8
0
 public static void ReadPart <T>(T instance, BarfDeserializationArgs args, PartFlags flags)
     where T : class
 {
     ReadPart <T>(ref instance, args, flags);
 }