Example #1
0
        void ISaveStream.SerializeBlock <TType>(string name, ref TType value)
        {
            if (this.Stream.ReadValueU32() != 0x4B434C42) // BLCK
            {
                throw new FormatException();
            }

            var actualName = this.Stream.ReadEncodedString();

            if (name != actualName)
            {
                throw new FormatException();
            }

            var size = this.Stream.ReadValueU32();
            var data = new byte[size];

            if (this.Stream.Read(data, 0, data.Length) != data.Length)
            {
                throw new FormatException();
            }

            using (var reader = new SaveReader(data))
            {
                var instance = new TType();
                instance.Serialize(reader);

                if (reader.Stream.Position != reader.Stream.Length)
                {
                    throw new FormatException();
                }

                value = instance;
            }
        }
Example #2
0
        void ISaveStream.SerializeBlocks <TType>(
            string name, string type, ref List <TType> value)
        {
            if (this.Stream.ReadValueU32() != 0x4B434C42) // BLCK
            {
                throw new FormatException();
            }

            var actualName = this.Stream.ReadEncodedString();

            if (name != actualName)
            {
                throw new FormatException();
            }

            var size = this.Stream.ReadValueU32();
            var data = new byte[size];

            if (this.Stream.Read(data, 0, data.Length) != data.Length)
            {
                throw new FormatException();
            }

            using (var reader = new SaveReader(data))
            {
                var list = new List <TType>();
                while (reader.Stream.Position < reader.Stream.Length)
                {
                    var instance = new TType();
                    ((ISaveStream)reader).SerializeBlock(type, ref instance);
                    list.Add(instance);
                }
                value = list;
            }
        }
Example #3
0
        void ISaveStream.SerializeObject <TType>(
            string name, string type, ref TType value)
        {
            var data = this.ReadValue(name, type);

            using (var reader = new SaveReader(data))
            {
                var instance = new TType();
                instance.Serialize(reader);
                value = instance;
            }
        }
Example #4
0
        void ISaveStream.SerializeObject <TType>(
            // ReSharper disable RedundantAssignment
            string name, string type, ref TType value)
        // ReSharper restore RedundantAssignment
        {
            var data = this.ReadValue(name, type);

            using (var reader = new SaveReader(data))
            {
                var instance = new TType();
                instance.Serialize(reader);
                value = instance;
            }
        }