/// <summary> /// Analyze the provided buffer and returns a collection of packets represented by the buffer /// </summary> public static BonCodeAJP13PacketCollection GetPackets(byte[] Buffer) { BonCodeAJP13PacketCollection AnalyzedResponses = new BonCodeAJP13PacketCollection(); if (Buffer != null) { int start = 0; for (int i = 0; i < Buffer.Length; i++) { if (Buffer[start] == BonCodeAJP13PacketFormat.BONCODEAJP13_PACKET_START) { UInt16 UserDataLength = 0; GetUInt16(Buffer, ref UserDataLength, start + USERDATALENGTH_POS); i = start + UserDataLength + 8; // here we need to truncate the buffer and analyze the packet. if (Buffer[i] == BonCodeAJP13PacketFormat.BONCODEAJP13_PACKET_END) { byte[] NewPacket = new byte[i + 1 - start]; Array.Copy(Buffer, start, NewPacket, 0, i + 1 - start); BonCodeAJP13Packet packet = BonCodeAJP13Packet.GetPacket(NewPacket); if (packet != null) { AnalyzedResponses.Add(packet); } else { return(null); } start = i + 1; } else { return(null); } } else { return(null); } } return(AnalyzedResponses); } else { return(null); } }