public static EventValidationStore DeserializeFrom(Stream inputStream) { // don't need a 'using' block around this reader DeserializingBinaryReader reader = new DeserializingBinaryReader(inputStream); byte versionHeader = reader.ReadByte(); if (versionHeader != (byte)0x00) { // the only version we support is v0; throw if unsupported throw new InvalidOperationException(SR.GetString(SR.InvalidSerializedData)); } EventValidationStore store = new EventValidationStore(); // 'numEntries' is the number of HASH_SIZE_IN_BYTES-sized entries // we should expect in the stream. int numEntries = reader.Read7BitEncodedInt(); for (int i = 0; i < numEntries; i++) { byte[] entry = reader.ReadBytes(HASH_SIZE_IN_BYTES); if (entry.Length != HASH_SIZE_IN_BYTES) { // bad data (EOF) throw new InvalidOperationException(SR.GetString(SR.InvalidSerializedData)); } store._hashes.Add(entry); } return(store); }
// Creates a duplicate store seeded with the same hashes as the current store. public EventValidationStore Clone() { EventValidationStore newStore = new EventValidationStore(); newStore._hashes.UnionWith(this._hashes); return(newStore); }