public static Message Deserialize(BinaryReader reader, Func <long, IDescriptor> find) { long ID = reader.ReadInt64(); IDescriptor description = null; CommandPersist persist = new CommandPersist(null, null); if (ID > 0) { try { description = PreviousRecord.Key == ID ? PreviousRecord.Value : find(ID); persist = new CommandPersist(new DataPersist(description.KeyType, null, AllowNull.OnlyMembers), new DataPersist(description.RecordType, null, AllowNull.OnlyMembers)); } catch (Exception exc) { throw new Exception("Cannot find description with the specified ID"); } if (PreviousRecord.Key != ID) { PreviousRecord = new KeyValuePair <long, IDescriptor>(ID, description); } } var commandsPersist = new CommandCollectionPersist(persist); CommandCollection commands = commandsPersist.Read(reader); return(new Message(description, commands)); }
public void Serialize(BinaryWriter writer) { long ID = Description.ID; writer.Write(ID); CommandPersist persist = ID > 0 ? new CommandPersist(new DataPersist(Description.KeyType, null, AllowNull.OnlyMembers), new DataPersist(Description.RecordType, null, AllowNull.OnlyMembers)) : new CommandPersist(null, null); CommandCollectionPersist commandsPersist = new CommandCollectionPersist(persist); commandsPersist.Write(writer, Commands); }