示例#1
0
        private void WriteIndices(BinaryWriter writer, WDB2RowSerializer <T> serializer, uint layoutHash)
        {
            int min = serializer.Records.Keys.Min();
            int max = serializer.Records.Keys.Max();

            writer.Write(min);
            writer.Write(max);
            writer.Write(layoutHash);
            writer.Write(0); // CopyTableSize

            int index = 0;

            for (int i = min; i <= max; i++)
            {
                if (serializer.StringLengths.ContainsKey(i))
                {
                    writer.Write(++index);
                    writer.Write(serializer.StringLengths[i]);
                }
                else
                {
                    writer.Write(0);
                    writer.Write((ushort)0);
                }
            }
        }
示例#2
0
        private const uint WDB2FmtSig = 0x32424457; // WDB2

        public WDB2Writer(WDB2Reader reader, IDictionary <int, T> storage, Stream stream) : base(reader)
        {
            WDB2RowSerializer <T> serializer = new WDB2RowSerializer <T>(this);

            serializer.Serialize(storage);

            RecordsCount = storage.Count;

            using (var writer = new BinaryWriter(stream))
            {
                writer.Write(WDB2FmtSig);
                writer.Write(RecordsCount);
                writer.Write(FieldsCount);
                writer.Write(RecordSize);
                writer.Write(StringTableSize);
                writer.Write(reader.TableHash);
                writer.Write(reader.Build);
                writer.Write((uint)DateTimeOffset.UtcNow.ToUnixTimeSeconds());

                if (storage.Count == 0)
                {
                    return;
                }

                // Extended header
                if (reader.Build > 12880)
                {
                    if (reader.MaxIndex == 0)
                    {
                        writer.Write(0);
                        writer.Write(0);
                        writer.Write(reader.LayoutHash);
                        writer.Write(0); // CopyTableSize
                    }
                    else
                    {
                        WriteIndices(writer, serializer, reader.LayoutHash);
                    }
                }

                foreach (var record in serializer.Records)
                {
                    record.Value.CopyTo(writer.BaseStream);
                }

                foreach (var str in StringTable)
                {
                    writer.WriteCString(str.Key);
                }
            }
        }