예제 #1
0
        public void Deserialize(Package package, uint elementCount)
        {
            if (package.Header.Version >= PackageVersion.Hydra_V0_1)
            {
                throw new ArgumentException("Obsolete deserialization method called.");
            }

            for (var index = 0; index < elementCount; index++)
            {
                var element = new ObjectTableEntry();
                package.DeserializeObject(element);
                _elements.Add(element);
            }
        }
예제 #2
0
        public void Deserialize(Package package)
        {
            if (package.Header.Version < PackageVersion.Hydra_V0_1)
            {
                throw new ArgumentException("Object table cannot be deserialized without a known size.");
            }

            var elementCount = package.ReadUInt16();

            for (var index = 0; index < elementCount; index++)
            {
                var element = new ObjectTableEntry();
                package.DeserializeObject(element);
                _elements.Add(element);
            }
        }
예제 #3
0
        public void Serialize(Package package)
        {
            if (package.Header.Version < PackageVersion.Hydra_V0_1)
            {
                throw new ArgumentException($"Serialization of object tables to versions older than {PackageVersion.Hydra_V0_1} is unsupported.");
            }

            package.WriteUInt16((ushort)_serializationQueue.Count);
            var index = 0u;

            foreach (var serializable in _serializationQueue)
            {
                var entry = new ObjectTableEntry();
                entry.Index = new ObjectIndex(index);

                entry.TypeIndex = 0;
                if (serializable != null)
                {
                    foreach (var attribute in TypeDescriptor.GetAttributes(serializable.GetType()))
                    {
                        if (attribute is SerializableObjectTypeAttribute)
                        {
                            var typeInfo = (SerializableObjectTypeAttribute)attribute;
                            Console.WriteLine(
                                $"save: reflect: {serializable} => {typeInfo.TypeIndex} since {typeInfo.FormatVersion} (current {package.Header.Version})");
                            if (typeInfo.FormatVersion <= package.Header.Version)
                            {
                                entry.TypeIndex = (ushort)typeInfo.TypeIndex;
                                break;
                            }
                        }
                    }
                }

                entry.LinkedObject = serializable;
                _elements.Add(entry);
                package.SerializeObject(entry);
                index++;
            }
        }