Esempio n. 1
0
        /// <summary>
        /// Parse to COTP
        /// </summary>
        /// <param name="header"></param>
        /// <returns></returns>
        private void ParseEncapsulatedBytes()
        {
            ByteArraySegment payload;

            payload = this.header.EncapsulatedBytes();
            this.payloadPacketOrData = new PacketOrByteArraySegment();
            if (payload.Length > Length - TpktFileds.HeaderLength)
            {
                BuildSegments(payload, Math.Min(Length - TpktFileds.HeaderLength, payload.Length));
                this.payloadPacketOrData.TheByteArraySegment = payload;
            }
            else if (payload.Length == Length - TpktFileds.HeaderLength)
            {
                HasSegments            = false;
                NextFrameSegmentLength = 0;
                // TODO: Check if payload is COTP
                byte[] header = payload.ActualBytes().Take(CotpFileds.HeaderLength).ToArray();
                if (CotpPacket.IsCotp(header))
                {
                    this.payloadPacketOrData.ThePacket = new CotpPacket(payload, this);
                }
                else
                {
                    this.payloadPacketOrData.TheByteArraySegment = payload;
                }
            }
            else
            {
                this.header.Length = 0;
                this.payloadPacketOrData.TheByteArraySegment = this.header.EncapsulatedBytes();
                payload = this.payloadPacketOrData.TheByteArraySegment;
                BuildSegments(payload, payload.Length);
                this.Length = 0;
            }
        }
Esempio n. 2
0
 public void Add(CotpPacket packet)
 {
     packetBuffer.Add(packet);
     if (packet.LastDataUnit)
     {
         Reasseble();
     }
 }
Esempio n. 3
0
        /// <summary>
        /// Reaseemble the packets in Buffer, and flush it.
        /// </summary>
        private void Reasseble()
        {
            ReSort();
            List <byte> joint = new List <byte>();

            joint.AddRange(packetBuffer[packetBuffer.Count - 1].Header);
            foreach (Packet i in packetBuffer)
            {
                joint.AddRange(i.PayloadData);
            }

            Reassembled = new CotpPacket(new ByteArraySegment(joint.ToArray()), packetBuffer[packetBuffer.Count - 1].ParentPacket);
            joint.Clear();
            joint         = null;
            IsReassembled = true;
            packetBuffer.Clear();
        }
Esempio n. 4
0
 public CotpPacketBuffer(CotpPacket packet)
     : this()
 {
     Add(packet);
 }