public PacketLogEntry ReadNextLogEntry() { try { var ticks = inputStreamReader.ReadInt64(); var directionCode = (DiagnosticStreamDirection)inputStreamReader.ReadUInt32(); var direction = directionCode == DiagnosticStreamDirection.ClientToServer ? PacketDirection.ProxyServer : directionCode == DiagnosticStreamDirection.ServerToClient ? PacketDirection.ProxyClient : throw new InvalidOperationException(); var packet = packetLogParser.ParsePacket(pullStream); var name = packetRegistry.Find(packet.Id).Name; return(new PacketLogEntry(new DateTime(ticks), name, direction, packet.Payload)); } catch (EndOfStreamException) { return(null); } }
public IEnumerable <PacketLogEntry> ParseFile(string fileName) { using (var stream = new FileStream(fileName, FileMode.Open)) { using (var reader = new BinaryReader(stream)) { using (var pullStream = new StreamToPullStreamAdapter(stream)) { while (stream.Position < stream.Length) { var time = new DateTime(reader.ReadInt64(), DateTimeKind.Utc); var binaryDirection = (DiagnosticStreamDirection)reader.ReadInt32(); PacketDirection packetDirection; switch (binaryDirection) { case DiagnosticStreamDirection.ClientToServer: packetDirection = PacketDirection.ProxyServer; break; case DiagnosticStreamDirection.ServerToClient: packetDirection = PacketDirection.ProxyClient; break; default: throw new NotImplementedException($"Unknown binnary packet direction: {((int)binaryDirection):X8} at position {stream.Position}"); } var packet = packetLogParser.ParsePacket(pullStream); var definition = packetRegistry.Find(packet.Id); yield return(new PacketLogEntry(time, definition.Name, packetDirection, packet.Payload)); } } } } }