private void Reassemble()
        {
            //  ReSort();

            Reassembled = new List <TpktPacket>();
            segBuffer.AddRange(packetBuffer[0].Header);
            segBuffer.AddRange(packetBuffer[0].PayloadData);
            if (packetBuffer[0].Length == segBuffer.Count)
            {
                Reassembled.Add(new TpktPacket(segBuffer.ToArray(), packetBuffer[0].ParentPacket));
                segBuffer.Clear();
            }

            Reassemble(packetBuffer[0].TpktSegments, 0);

            for (int i = 1; i < Count; i++)
            {
                TpktPacket p = packetBuffer[i];
                Reassemble(p.TpktSegments, i);
            }
            if (segBuffer.Count > 0)
            {
                Reassembled.Add(new TpktPacket(segBuffer.ToArray(), packetBuffer[Count - 1].ParentPacket));
                segBuffer.Clear();
                //      pos = segBuffer.Count;
            }
            IsReassembled = true;
        }
        /// <summary>
        /// If the given TPKT packet doesn't contain segments, it will be added into <see cref="IEC61850Packet.TpktPacketBuffer.Reassembled"/>,
        /// </summary>
        /// <param name="packet"></param>
        public void Add(TpktPacket packet)
        {
            if (!packet.HasSegments)
            {
                Reassembled.Add(packet);

                IsReassembled = true;
            }
            else
            {
                packetBuffer.Add(packet);
                if (packet.LastSegment)
                {
                    Reassemble();
                }
            }
        }
 public TpktPacketBuffer(TpktPacket packet)
     : this()
 {
     Add(packet);
 }