diff --git a/src/StructuredLogger/Serialization/Binary/BinaryLogReader.cs b/src/StructuredLogger/Serialization/Binary/BinaryLogReader.cs index 05e6286c..daa078a9 100644 --- a/src/StructuredLogger/Serialization/Binary/BinaryLogReader.cs +++ b/src/StructuredLogger/Serialization/Binary/BinaryLogReader.cs @@ -11,6 +11,7 @@ public class BinaryLogReader : IDisposable private readonly Queue attributes = new Queue(10); private readonly bool formatSupportsSourceFiles; + private readonly bool formatSupportsEmbeddedProjectImportsArchive; public static Build Read(string filePath) { @@ -25,7 +26,7 @@ public static Build Read(string filePath) } var projectImportsZip = Path.ChangeExtension(filePath, ".ProjectImports.zip"); - if (File.Exists(projectImportsZip)) + if (build.SourceFilesArchive == null && File.Exists(projectImportsZip)) { build.SourceFilesArchive = File.ReadAllBytes(projectImportsZip); } @@ -39,6 +40,7 @@ private BinaryLogReader(string filePath) this.filePath = filePath; this.reader = new TreeBinaryReader(filePath); this.formatSupportsSourceFiles = reader.Version > new Version(1, 0, 130); + this.formatSupportsEmbeddedProjectImportsArchive = reader.Version > new Version(1, 1, 87); } private object ReadNode() @@ -64,6 +66,11 @@ private object ReadNode() } } + if (node is Build build && formatSupportsEmbeddedProjectImportsArchive) + { + build.SourceFilesArchive = reader.ReadByteArray(); + } + return node; } diff --git a/src/StructuredLogger/Serialization/Binary/BinaryLogWriter.cs b/src/StructuredLogger/Serialization/Binary/BinaryLogWriter.cs index 92cf3a6c..801ed797 100644 --- a/src/StructuredLogger/Serialization/Binary/BinaryLogWriter.cs +++ b/src/StructuredLogger/Serialization/Binary/BinaryLogWriter.cs @@ -27,6 +27,11 @@ private void WriteNode(object node) WriteAttributes(node); writer.WriteEndAttributes(); WriteChildren(node); + + if (node is Build build) + { + writer.WriteByteArray(build.SourceFilesArchive); + } } private void WriteChildren(object node) diff --git a/src/StructuredLogger/Serialization/Binary/TreeBinaryReader.cs b/src/StructuredLogger/Serialization/Binary/TreeBinaryReader.cs index 5e65e5f4..c310d5d5 100644 --- a/src/StructuredLogger/Serialization/Binary/TreeBinaryReader.cs +++ b/src/StructuredLogger/Serialization/Binary/TreeBinaryReader.cs @@ -38,6 +38,17 @@ public TreeBinaryReader(string filePath) public string[] StringTable => stringTable; + public byte[] ReadByteArray() + { + int length = binaryReader.ReadInt32(); + if (length > 0) + { + return binaryReader.ReadBytes(length); + } + + return null; + } + public void ReadStringArray(Queue array) { array.Clear(); diff --git a/src/StructuredLogger/Serialization/Binary/TreeBinaryWriter.cs b/src/StructuredLogger/Serialization/Binary/TreeBinaryWriter.cs index 45f12372..cddce848 100644 --- a/src/StructuredLogger/Serialization/Binary/TreeBinaryWriter.cs +++ b/src/StructuredLogger/Serialization/Binary/TreeBinaryWriter.cs @@ -100,6 +100,16 @@ private void WriteStringTable() } } + public void WriteByteArray(byte[] bytes) + { + bytes = bytes ?? Array.Empty(); + treeNodesStreamBinaryWriter.Write(bytes.Length); + if (bytes.Length > 0) + { + treeNodesStreamBinaryWriter.Write(bytes); + } + } + private Stream DestinationStream => gzipStream; public void Dispose()