using System; using System.Collections.Generic; using System.Text; namespace CommonLib.IO.File { /// /// 表示捕获到的包。 /// public sealed class PacketCapture { private readonly UnixTime _Timestamp; private readonly ArraySegment _Packet; private readonly int _RawLength; private readonly int _Millseconds; ///唯一有用的东西,其他的都是啥??? /// /// 构造一个捕获包 /// /// 包 /// 原始长度 /// 时间戳 /// 时间戳的微秒值 public PacketCapture(ArraySegment packet, int rawLength, UnixTime timestamp, int millseconds) { if (packet.Count > rawLength) throw new ArgumentException("包内容长度不能大于原始长度。", "rawLength"); _Packet = packet; _Timestamp = timestamp; _RawLength = rawLength; _Millseconds = millseconds; } /// /// 构造一个捕获包 /// /// 包 /// 原始长度 /// 时间戳 public PacketCapture(ArraySegment packet, int rawLength, DateTime timestamp) : this(packet, rawLength, UnixTime.FromDateTime(timestamp), 0) { } /// /// 构造一个捕获包 /// /// 包 /// 原始长度 public PacketCapture(ArraySegment packet, int rawLength) : this(packet, rawLength, UnixTime.FromDateTime(DateTime.Today), 0) { } /// /// 构造一个捕获包 /// /// 包 public PacketCapture(ArraySegment packet) : this(packet, packet.Count) { } /// /// 构造一个捕获包 /// /// 包数据 /// 数据的偏移。 /// 数据的大小。 /// 原始长度 /// 时间戳 /// 时间戳的微秒值 public PacketCapture(byte[] packetData, int offset, int count, int rawLength, UnixTime timestamp, int millseconds) : this(new ArraySegment(packetData, offset, count), rawLength, timestamp, millseconds) { } /// /// 构造一个捕获包 /// /// 包数据 /// 数据的偏移。 /// 数据的大小。 /// 原始长度 /// 时间戳 public PacketCapture(byte[] packetData, int offset, int count, int rawLength, DateTime timestamp) : this(new ArraySegment(packetData, offset, count), rawLength, UnixTime.FromDateTime(timestamp), 0) { } /// /// 构造一个捕获包 /// /// 包数据 /// 原始长度 /// 时间戳 /// 时间戳的微秒值 public PacketCapture(byte[] packetData, int rawLength, UnixTime timestamp, int millseconds) : this(new ArraySegment(packetData), rawLength, timestamp, millseconds) { } /// /// 构造一个捕获包 /// /// 包数据 /// 原始长度 /// 时间戳 public PacketCapture(byte[] packetData, int rawLength, DateTime timestamp) : this(new ArraySegment(packetData), rawLength, UnixTime.FromDateTime(timestamp), 0) { } /// /// 构造一个捕获包 /// /// 包数据 /// 原始长度 public PacketCapture(byte[] packetData, int rawLength) : this(new ArraySegment(packetData), rawLength, UnixTime.FromDateTime(DateTime.Today), 0) { } /// /// 构造一个捕获包 /// /// 包数据 public PacketCapture(byte[] packetData) : this(packetData, packetData.Length) { } /// /// 数据包内容 /// public ArraySegment Packet { get { return _Packet; } } /// /// 时间戳 /// public UnixTime Timestamp { get { return _Timestamp; } } /// /// 表示时间戳的微秒 /// public int Millseconds { get { return _Millseconds; } } /// /// 原始长度 /// public int RawLength { get { return _RawLength; } } } }