void WriteEntry(BufferWriter writer, JournalEntry entry) { writer.WriteInt64(entry.Address); writer.WriteInt32(entry.Data.Length); writer.WriteBytes(entry.Data); writer.WriteInt64(entry.Stamp); var streamNameBytes = Encoding.UTF8.GetBytes(entry.StreamName); writer.WriteInt32(streamNameBytes.Length); writer.WriteBytes(streamNameBytes); }
public byte[] Serialize(Node <EmptyRecordIndexKey> node) { var bytes = new byte[MaxSizeForDegree(node.Degree)]; var writer = new BufferWriter(bytes); writer.WriteInt32(node.Degree); //Degree writer.WriteInt32(node.EntryList.Count); //Nr of entries foreach (var entry in node.EntryList.Entries) { WriteEntry(writer, entry); //every entry } writer.WriteInt32(node.ChildrenAddresses.Count); //Nr of child addresses foreach (var childAddress in node.ChildrenAddresses.Addresses) { writer.WriteInt64(childAddress); //every child address } return(writer.Buffer); }
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()); }
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()); }
void WriteEntry(BufferWriter writer, Entry <EmptyRecordIndexKey> entry) { writer.WriteInt32(entry.Key.S); //Size writer.WriteInt64(entry.Key.A); //Address writer.WriteInt64(entry.Pointer); //Pointer (which is address too); }