/// <summary> /// When overriden in a derived class, writes the packet data to a byte array. /// </summary> /// <returns>The byte array that contains the packet structure.</returns> public virtual byte[] Save() { byte[] result; using (var writer = new StreamHandler()) { Save(writer); result = writer.ToByteArray(); } return(result); }
protected unsafe override void InternalWriteMetaData() { m_stream.DoAt(m_streamOriginalPosition, () => { var bytes = new byte[MainHeader.Size]; byte[] extraData; using (var writer = new StreamHandler()) { var flags = this.ExtraInfoFlags; if (flags.HasFlag(ExtraDataFlags.HasClientIPv4) || flags.HasFlag(ExtraDataFlags.HasClientIPv6)) writer.WriteBytes(this.ClientAddress.GetAddressBytes()); if (flags.HasFlag(ExtraDataFlags.HasServerIPv4) || flags.HasFlag(ExtraDataFlags.HasServerIPv6)) writer.WriteBytes(this.ServerAddress.GetAddressBytes()); if (flags.HasFlag(ExtraDataFlags.HasClientPort)) writer.WriteInt32(this.ClientPort); if (flags.HasFlag(ExtraDataFlags.HasServerPort)) writer.WriteInt32(this.ServerPort); if (flags.HasFlag(ExtraDataFlags.HasSnifferIdString)) { byte[] arr = Encoding.UTF8.GetBytes(this.SnifferDesc ?? string.Empty); writer.WriteInt32(arr.Length); using (MemoryStream oStream = new MemoryStream()) { // BUG http://blogs.msdn.com/b/bclteam/archive/2006/05/10/592551.aspx using (var ds = new DeflateStream(oStream, CompressionMode.Compress, true)) ds.Write(arr, 0, arr.Length); arr = oStream.ToArray(); } writer.WriteInt32(arr.Length); writer.WriteBytes(arr); } extraData = writer.ToByteArray(); } fixed (byte* bytesPtr = bytes) { var header = (MainHeader*)bytesPtr; header->PacketCount = this.Count; Marshal.Copy(SignatureBytes, 0, new IntPtr(header->Signature), SignatureBytes.Length); header->StartedOnTicks = this.StartTicks; header->StartedOnUnix = this.StartTime.ToUnixTime(); header->ExtraDataLength = extraData.Length; header->ExtraInfoFlags = this.ExtraInfoFlags; } m_stream.WriteBytes(bytes); m_stream.WriteBytes(extraData); }); }
protected override unsafe void InternalWriteMetaData() { m_stream.DoAt(m_streamOriginalPosition, () => { var bytes = new byte[MainHeader.Size]; byte[] extraData; using (var writer = new StreamHandler()) { var flags = this.ExtraInfoFlags; if (flags.HasFlag(ExtraDataFlags.HasClientIPv4) || flags.HasFlag(ExtraDataFlags.HasClientIPv6)) { writer.WriteBytes(this.ClientAddress.GetAddressBytes()); } if (flags.HasFlag(ExtraDataFlags.HasServerIPv4) || flags.HasFlag(ExtraDataFlags.HasServerIPv6)) { writer.WriteBytes(this.ServerAddress.GetAddressBytes()); } if (flags.HasFlag(ExtraDataFlags.HasClientPort)) { writer.WriteInt32(this.ClientPort); } if (flags.HasFlag(ExtraDataFlags.HasServerPort)) { writer.WriteInt32(this.ServerPort); } if (flags.HasFlag(ExtraDataFlags.HasSnifferIdString)) { byte[] arr = Encoding.UTF8.GetBytes(this.SnifferDesc ?? string.Empty); writer.WriteInt32(arr.Length); using (MemoryStream oStream = new MemoryStream()) { // BUG http://blogs.msdn.com/b/bclteam/archive/2006/05/10/592551.aspx using (var ds = new DeflateStream(oStream, CompressionMode.Compress, true)) ds.Write(arr, 0, arr.Length); arr = oStream.ToArray(); } writer.WriteInt32(arr.Length); writer.WriteBytes(arr); } extraData = writer.ToByteArray(); } fixed(byte *bytesPtr = bytes) { var header = (MainHeader *)bytesPtr; header->PacketCount = this.Count; Marshal.Copy(SignatureBytes, 0, new IntPtr(header->Signature), SignatureBytes.Length); header->StartedOnTicks = this.StartTicks; header->StartedOnUnix = this.StartTime.ToUnixTime(); header->ExtraDataLength = extraData.Length; header->ExtraInfoFlags = this.ExtraInfoFlags; } m_stream.WriteBytes(bytes); m_stream.WriteBytes(extraData); }); }
/// <summary> /// When overriden in a derived class, writes the packet data to a byte array. /// </summary> /// <returns>The byte array that contains the packet structure.</returns> public virtual byte[] Save() { byte[] result; using (var writer = new StreamHandler()) { Save(writer); result = writer.ToByteArray(); } return result; }