/// <summary>
        /// Reads <see cref="SerializerData"/> from a stream using a
        /// <see cref="BinaryReader"/>.
        /// </summary>
        /// <param name="metaData">The metadata of the stored data.</param>
        public static SerializerData Read(BinaryReader reader, List <SerializerMetaData> metaData)
        {
            long startPosition = reader.BaseStream.Position;
            var  result        = new SerializerData();

            foreach (var meta in metaData)
            {
                reader.BaseStream.Seek(startPosition + meta.Position, SeekOrigin.Begin);
                object value = result.Read(reader, meta.Type);

                result.ObjectData.Add(meta, value);
            }

            return(result);
        }
Exemple #2
0
        /// <summary>
        /// Reads serialized data into an <see cref="ISerializableGameObject"/>
        /// from stream using a BinaryReader.
        /// </summary>
        private void ReadGameObject(BinaryReader reader, ISerializableGameObject gameObject)
        {
            Version readVersion = reader.ReadVersion();

            // Read meta data
            var metaData = ReadAllMetaData(reader, gameObject.ExpectedData(readVersion));

            // Read data length
            long length = reader.ReadInt64();

            // Read data
            long startPosition = reader.BaseStream.Position;
            var  data          = SerializerData.Read(reader, metaData);

            reader.BaseStream.Seek(startPosition + length, SeekOrigin.Begin);

            gameObject.UpdateReadValues(readVersion, data);
            gameObject.SetReadValues(data);
        }