Exemplo n.º 1
0
        => 1 + 4 + 4 + 4;     // Type + Page Offset + Date + Size

        public override void SerializeTypeMeta(ref SpanWriter writer)
        {
            writer.WriteByte((byte)EntryType);

            writer.WriteInt32(PageOffset);
            writer.WriteDateTimeT(ModifiedDate);
            writer.WriteInt32(Size);
        }
Exemplo n.º 2
0
        private protected int WriteAnnouncement(Span <byte> output, int entriesCount)
        {
            var writer = new SpanWriter <byte>(output);

            writer.WriteUInt16(myPort, true);
            writer.WriteInt64(term, true);
            writer.WriteInt64(prevLogIndex, true);
            writer.WriteInt64(prevLogTerm, true);
            writer.WriteInt64(commitIndex, true);
            writer.WriteInt32(entriesCount, true);

            return(writer.WrittenCount);
        }
Exemplo n.º 3
0
        public void WriteEntry(Entry entry)
        {
            int entrySize = entry.GetTotalSize(LastPosition);

            if (entrySize + TocEntrySize > _spaceLeft)
            {
                throw new Exception("Not enough space to write entry.");
            }

            if (EntryCount == 0)
            {
                FirstEntry = entry;
            }

            SpanWriter blockWriter = new SpanWriter(Buffer);

            blockWriter.Position = LastPosition;

            // Begin to write the entry's common information
            // Not actually BE, both are writen as indexing buffer
            int entryOffset = blockWriter.Position;

            blockWriter.Endian = Endian.Big;
            blockWriter.WriteInt32(entry.ParentNode);
            blockWriter.Endian = Endian.Little;
            blockWriter.WriteStringRaw(entry.Name);
            blockWriter.Align(0x04); // Entry is aligned

            // Write type specific
            int entryMetaOffset = blockWriter.Position;

            entry.SerializeTypeMeta(ref blockWriter);
            blockWriter.Align(0x04); // Whole entry is also aligned

            LastPosition = blockWriter.Position;
            _spaceLeft  -= entrySize + TocEntrySize; // Include the block's toc entry

            // Write the lookup information at the end of the block
            blockWriter.Position = BlockSize - ((EntryCount + 1) * TocEntrySize);
            blockWriter.WriteUInt16((ushort)entryOffset);
            blockWriter.WriteUInt16((ushort)entry.GetEntryMetaSize());
            blockWriter.WriteUInt16((ushort)entryMetaOffset);
            blockWriter.WriteUInt16(entry.GetTypeMetaSize());

            // Move on to next.
            EntryCount++;
        }