NetworkCommsDotNet.Tools.PacketBuilder.AddPartialPacket C# (CSharp) Method

AddPartialPacket() public method

Add a partial packet to the end of the cache by reference.
public AddPartialPacket ( int packetBytes, byte partialPacket ) : void
packetBytes int The number of valid bytes in the provided partial packet
partialPacket byte A buffer which may or may not be full with valid bytes
return void
        public void AddPartialPacket(int packetBytes, byte[] partialPacket)
        {
            if (packetBytes > partialPacket.Length)
                throw new ArgumentException("packetBytes cannot be greater than the length of the provided partialPacket data.");
            if (packetBytes < 0)
                throw new ArgumentException("packetBytes cannot be negative.");

            lock (Locker)
            {
                totalBytesCached += packetBytes;

                packets.Add(partialPacket);
                packetActualBytes.Add(packetBytes);

                if (NetworkComms.LoggingEnabled)
                {
                    if (TotalBytesExpected == 0 && totalBytesCached > (10 * 1024 * 1024))
                        NetworkComms.Logger.Warn("Packet builder cache contains " + (totalBytesCached / 1024.0).ToString("0.0") + "KB when 0KB are currently expected.");
                    else if (TotalBytesExpected > 0 && totalBytesCached > totalBytesExpected * 2)
                        NetworkComms.Logger.Warn("Packet builder cache contains " + (totalBytesCached / 1024.0).ToString("0.0") + "KB when only " + (TotalBytesExpected / 1024.0).ToString("0.0") + "KB were expected.");
                }

                if (NetworkComms.LoggingEnabled) NetworkComms.Logger.Trace(" ... added " + packetBytes + " bytes to packetBuilder.");
            }
        }