namespace Supercell.Laser.Server.Networking { using System; using System.IO; using System.Text; // Opt-in packet capture for comparing the C# wire format with the Zig // implementation. Enable with BS_WIRE_DUMP=1. internal static class WireDump { private static readonly object Sync = new object(); private static readonly string Path = Environment.GetEnvironmentVariable("BS_WIRE_DUMP_PATH") ?? "/tmp/bsav36-csharp-wire.log"; public static void Write(string direction, byte[] data, int offset, int length) { if (Environment.GetEnvironmentVariable("BS_WIRE_DUMP") != "1") return; if (data == null || offset < 0 || length < 0 || offset + length > data.Length) return; var hex = new StringBuilder(length * 2); for (int i = offset; i < offset + length; i++) hex.Append(data[i].ToString("X2")); lock (Sync) { File.AppendAllText(Path, $"{DateTime.UtcNow:O} {direction} len={length} hex={hex}\n", Encoding.ASCII); } } } }