public IEnumerable <Record> ReadRecordsFromDecompressedStream(Stream decompressedStream) { var wrapper = new WrapperStream(decompressedStream); var binaryReader = new BinaryReader(wrapper); int fileFormatVersion = binaryReader.ReadInt32(); // the log file is written using a newer version of file format // that we don't know how to read if (fileFormatVersion > BinaryLogger.FileFormatVersion) { var text = $"Unsupported log file format. Latest supported version is {BinaryLogger.FileFormatVersion}, the log file has version {fileFormatVersion}."; throw new NotSupportedException(text); } long lengthOfBlobsAddedLastTime = 0; List <Record> blobs = new List <Record>(); using var reader = new BuildEventArgsReader(binaryReader, fileFormatVersion); // forward the events from the reader to the subscribers of this class reader.OnBlobRead += OnBlobRead; long start = 0; reader.OnBlobRead += (kind, blob) => { start = wrapper.Position; var record = new Record { Bytes = blob, Args = null, Start = start - blob.Length, // TODO: check if this is accurate Length = blob.Length }; blobs.Add(record); lengthOfBlobsAddedLastTime += blob.Length; }; reader.OnStringRead += text => { long length = wrapper.Position - start; // re-read the current position as we're just about to start reading // the actual BuildEventArgs record start = wrapper.Position; OnStringRead?.Invoke(text, length); }; reader.OnNameValueListRead += list => { long length = wrapper.Position - start; start = wrapper.Position; OnNameValueListRead?.Invoke(list, length); }; while (true) { BuildEventArgs instance = null; start = wrapper.Position; instance = reader.Read(); if (instance == null) { break; } var record = new Record { Bytes = null, // probably can reconstruct this from the Args if necessary Args = instance, Start = start, Length = wrapper.Position - start }; yield return(record); lengthOfBlobsAddedLastTime = 0; } foreach (var blob in blobs) { yield return(blob); } }
public IEnumerable <Record> ReadRecordsFromDecompressedStream(Stream decompressedStream) { var wrapper = new WrapperStream(decompressedStream); var binaryReader = new BinaryReader(wrapper); int fileFormatVersion = binaryReader.ReadInt32(); // the log file is written using a newer version of file format // that we don't know how to read if (fileFormatVersion > BinaryLogger.FileFormatVersion) { var text = $"Unsupported log file format. Latest supported version is {BinaryLogger.FileFormatVersion}, the log file has version {fileFormatVersion}."; throw new NotSupportedException(text); } long lengthOfBlobsAddedLastTime = 0; List <Record> blobs = new List <Record>(); var reader = new BuildEventArgsReader(binaryReader, fileFormatVersion); reader.OnBlobRead += (kind, blob) => { var record = new Record { Bytes = blob, Args = null, Start = 0, // TODO: see if we can re-add that Length = blob.Length }; blobs.Add(record); lengthOfBlobsAddedLastTime += blob.Length; }; while (true) { BuildEventArgs instance = null; long start = wrapper.Position; instance = reader.Read(); if (instance == null) { break; } var record = new Record { Bytes = null, // probably can reconstruct this from the Args if necessary Args = instance, Start = start, Length = wrapper.Position - start }; yield return(record); lengthOfBlobsAddedLastTime = 0; } foreach (var blob in blobs) { yield return(blob); } }