public void Deserialize(BinaryReader reader)
        {
            uint itemCount = reader.ReadUInt32();

            if (itemCount > reader.StreamRemainder())
            {
                throw new Exception("Array item count is out of bounds");
            }

            if (typeof(T) == typeof(byte))
            {
                // Avoid wasting time on large arrays
                if (itemCount > 0)
                {
                    (this as List <byte>).AddRange(reader.ReadBytes(itemCount));
                }
            }
            else
            {
                for (uint i = 0; i < itemCount; i++)
                {
                    var newObj = RTTI.DeserializeType <T>(reader);

                    Add(newObj);
                }
            }
        }
Esempio n. 2
0
        public static T Clone <T>(T obj)
        {
            if (obj == null)
            {
                return(default(T));
            }

            using var ms = new MemoryStream();
            using var bw = new BinaryWriter(ms);
            using var br = new BinaryReader(ms);

            RTTI.SerializeType(bw, obj);
            ms.Position = 0;
            return(RTTI.DeserializeType <T>(br));
        }
        public void Deserialize(BinaryReader reader)
        {
            uint itemCount = reader.ReadUInt32();

            if (itemCount > reader.StreamRemainder())
            {
                throw new Exception("HashSet item count is out of bounds");
            }

            for (uint i = 0; i < itemCount; i++)
            {
                uint entryHash = reader.ReadUInt32();
                var  newObj    = RTTI.DeserializeType <T>(reader);

                // TODO: is entryHash actually a hash?
                Add(entryHash, newObj);
            }
        }