protected unsafe override void InternalRead(Action<int> reportProgressDelegate) { int headerSize = ChunkHeader.Size; var headerBytes = new byte[headerSize]; fixed (byte* headerBytesPtr = headerBytes) { var header = (ChunkHeader*)headerBytesPtr; int progress = 0; var startTime = this.StartTime; var startTicks = this.StartTicks; for (int i = 0; i < m_nPackets; ++i) { if (m_stream.Read(headerBytes, 0, headerSize) != headerSize) throw new EndOfStreamException(); var packet = new Packet(m_stream.ReadBytes(header->DataLength), header->Direction, PacketFlags.None, this.StartTime.AddMilliseconds(header->TickCount - startTicks), header->TickCount); this.InternalAddPacket(packet); this.OnPacketAdded(packet); if (reportProgressDelegate != null) { int newProgress = i * 100 / m_nPackets; if (newProgress != progress) { progress = newProgress; reportProgressDelegate(progress); } } } } }
protected unsafe override void InternalWritePacket(Packet packet) { var bytes = new byte[ChunkHeader.Size]; fixed (byte* bytesPtr = bytes) { var header = (ChunkHeader*)bytesPtr; header->TickCount = packet.ArrivalTicks; header->Direction = packet.Direction; header->DataLength = packet.Data.Length; } m_stream.WriteBytes(bytes); m_stream.WriteBytes(packet.Data); }