Exemple #1
0
        private T ReadValue <T>(Guid itemId, bool isUser, Reader <T> reader)
        {
            MetadataEntryKey key = new MetadataEntryKey(itemId, isUser);
            MetadataEntry    entry;

            if (Table.Entries.TryGetValue(key, out entry))
            {
                _regionStream.Position = entry.Offset;
                byte[] data = Utilities.ReadFully(_regionStream, ReflectionHelper.SizeOf <T>());
                return(reader(data, 0));
            }

            return(default(T));
        }
Exemple #2
0
        private T ReadStruct <T>(Guid itemId, bool isUser)
            where T : IByteArraySerializable, new()
        {
            MetadataEntryKey key = new MetadataEntryKey(itemId, isUser);
            MetadataEntry    entry;

            if (Table.Entries.TryGetValue(key, out entry))
            {
                _regionStream.Position = entry.Offset;
                return(Utilities.ReadStruct <T>(_regionStream, (int)entry.Length));
            }

            return(default(T));
        }
Exemple #3
0
        private static uint AddEntryStruct <T>(T data, Guid id, MetadataEntryFlags flags, MetadataTable header, uint dataOffset, Stream stream)
            where T : IByteArraySerializable
        {
            MetadataEntryKey key   = new MetadataEntryKey(id, (flags & MetadataEntryFlags.IsUser) != 0);
            MetadataEntry    entry = new MetadataEntry();

            entry.ItemId = id;
            entry.Offset = dataOffset;
            entry.Length = (uint)data.Size;
            entry.Flags  = flags;

            header.Entries[key] = entry;

            stream.Position = dataOffset;
            Utilities.WriteStruct(stream, data);

            return(entry.Length);
        }
Exemple #4
0
        public int ReadFrom(byte[] buffer, int offset)
        {
            Array.Copy(buffer, offset, _headerData, 0, 32);

            Signature  = Utilities.ToUInt64LittleEndian(_headerData, 0);
            EntryCount = Utilities.ToUInt16LittleEndian(_headerData, 10);

            Entries = new Dictionary <MetadataEntryKey, MetadataEntry>();
            if (IsValid)
            {
                for (int i = 0; i < EntryCount; ++i)
                {
                    MetadataEntry entry = Utilities.ToStruct <MetadataEntry>(buffer, offset + 32 + (i * 32));
                    Entries[MetadataEntryKey.FromEntry(entry)] = entry;
                }
            }

            return(FixedSize);
        }
Exemple #5
0
        private static uint AddEntryValue <T>(T data, Writer <T> writer, Guid id, MetadataEntryFlags flags, MetadataTable header, uint dataOffset, Stream stream)
        {
            MetadataEntryKey key   = new MetadataEntryKey(id, (flags & MetadataEntryFlags.IsUser) != 0);
            MetadataEntry    entry = new MetadataEntry();

            entry.ItemId = id;
            entry.Offset = dataOffset;
            entry.Length = (uint)Marshal.SizeOf(typeof(T));
            entry.Flags  = flags;

            header.Entries[key] = entry;

            stream.Position = dataOffset;

            byte[] buffer = new byte[entry.Length];
            writer(data, buffer, 0);
            stream.Write(buffer, 0, buffer.Length);

            return(entry.Length);
        }