public byte[] Serialize(IndexMetaRecord record)
        {
            var bytes  = new byte[5 * sizeof(Int64)];
            var writer = new BufferWriter(bytes);

            writer.WriteInt64(record.RootNodeAddress);
            writer.WriteInt64(record.NumberOfEntries);
            writer.WriteInt64(record.NumberOfNodes);
            writer.WriteInt64(record.TotalAllocatedSize);
            writer.WriteInt64(record.TotalAllocatedDataSize);
            return(writer.GetTrimmedBuffer());
        }
        public byte[] Serialize(CollectionFileRoot root)
        {
            var expectedSize = sizeof(byte)
                               + sizeof(Int32)
                               + sizeof(Int64)
                               + sizeof(Int64);
            var writer = new BufferWriter(new byte[expectedSize]);

            writer.WriteByte(SERIALIZATION_VERSION);
            writer.WriteInt32(root.FormatVersion);
            writer.WriteInt64(root.Head);
            writer.WriteInt64(root.NamedRecordIndexAddress);

            return(writer.GetTrimmedBuffer());
        }
Пример #3
0
        public byte[] Serialize(TransactionJournal journal)
        {
            var expectedSize = sizeof(byte) + sizeof(Int32) + journal.Entries.Select(entry =>
            {
                return(sizeof(Int64) +
                       sizeof(Int32) +
                       entry.Data.Length +
                       sizeof(Int64) +
                       sizeof(Int32) + Encoding.UTF8.GetByteCount(entry.StreamName));
            }).Sum();

            var writer = new BufferWriter(new byte[expectedSize]);

            writer.WriteByte(FORMAT_VERSION);
            writer.WriteInt32(journal.Entries.Count);

            foreach (var entry in journal.Entries)
            {
                WriteEntry(writer, entry);
            }
            return(writer.GetTrimmedBuffer());
        }