/// <summary> /// Deserializes this packet from a binary stream. /// </summary> /// <param name="writer">PacketWriter used to deserialize the packet.</param> /// <param name="since">The minimum version of updates to pack.</param> public override void Write(PacketWriter writer, ReplicatedVersion since) { // Write the version vector only for root element if (this.Parent == null) { writer.Write(this.Version.NodeId); writer.Write(this.Version); } // Write a length (bookmark it) var bookmark = writer.Position; writer.Write(0); // Iterate through the values matching the 'since' constraint var count = 0; foreach (var entry in this.Map.Values) { // Ignore non-matching versions if (entry.Version < since.Of(entry.From)) { continue; } // Write the header writer.Write(entry.Version); writer.Write(entry.Deleted); writer.Write(entry.From); writer.Write(entry.Key); // Write the value only if we have it if (!entry.Deleted) { // Write the prefix if required this.WriteValuePrefix(entry.Value, writer); // Write the value itself writer.Write(entry.Value, since); } // Increment our pack count count++; } // Go back and write the final count var last = writer.Position; writer.Position = bookmark; writer.Write(count); writer.Position = last; }