Microsoft.Protocols.TestTools.StackSdk.RemoteDesktop.Rdpbcgr.RdpbcgrServerDecoder.GetPacket C# (CSharp) Method

GetPacket() private method

Get a complete packet buffer from received bytes
private GetPacket ( byte receivedBytes ) : byte[]
receivedBytes byte received bytes
return byte[]
        private byte[] GetPacket(byte[] receivedBytes)
        {
            if (receivedBytes == null || receivedBytes.Length == 0)
            {
                return null;
            }

            // Get packet length according to PDU type (slow-path/fast-path)
            int packetLength = 0;
            if (ConstValue.SLOW_PATH_PDU_INDICATOR_VALUE == receivedBytes[ConstValue.SLOW_PATH_PDU_INDICATOR_INDEX])
            {
                // Slow-path PDU
                if (receivedBytes.Length < Marshal.SizeOf(typeof(TpktHeader)))
                {
                    // the buffer doesn't contain the complete slow-path pdu header
                    return null;
                }

                // receivedBytes[2] and receivedBytes[3] make the length field of TpktHeader
                int tempIndex = 2;
                packetLength = ParseUInt16(receivedBytes, ref tempIndex, true);
            }
            else
            {
                // Fast-path PDU
                if (1 == receivedBytes.Length)
                {
                    // the buffer doesn't contain the complete fast-path pdu header
                    return null;
                }

                // "length2"(receivedBytes[2]) does not exists in received data
                // but "length1"(receivedBytes[1]) indicates that length2 exists
                if ((2 == receivedBytes.Length)
                    && ((receivedBytes[1] & ConstValue.MOST_SIGNIFICANT_BIT_FILTER) != receivedBytes[1]))
                {
                    return null;
                }

                // receivedBytes[1] and receivedBytes[2] are the corresponding
                // "length1" and "length2" fields in TS_FP_UPDATE_PDU
                packetLength = CalculateFpUpdatePduLength(receivedBytes[1], receivedBytes[2]);
            }

            // Received bytes does not contain enough data
            if (receivedBytes.Length < packetLength)
            {
                return null;
            }

            // Copy data to buffer
            byte[] buffer = new byte[packetLength];
            Array.Copy(receivedBytes, buffer, packetLength);
            return buffer;
        }
RdpbcgrServerDecoder