/// <summary>
        /// Create TransNamedRap request for client to send a rap request to server. 
        /// </summary>
        /// <param name = "messageId">the id of message, used to identity the request and the server response. </param>
        /// <param name = "sessionUid">the valid session id, must be response by server of the session setup request. </param>
        /// <param name = "treeId">the valid tree connect id, must be response by server of the tree connect. </param>
        /// <param name = "flags">
        /// The Flags field contains individual flags, as specified in [CIFS] sections 2.4.2 and 3.1.1. 
        /// </param>
        /// <param name = "flags2">
        /// The Flags2 field contains individual bit flags that, depending on the negotiated SMB dialect, indicate   
        /// various client and server capabilities. 
        /// </param>
        /// <param name = "transactOptions">
        /// A set of bit flags that alter the behavior of the requested operation. Unused bit fields MUST be set to  
        /// zero by the client sending the request, and MUST be ignored by the server receiving the request. The 
        /// client MAY set either or both of the following bit flags 
        /// </param>
        /// <param name="rapOPCode">
        /// The operation code for the particular operation. For more information on valid operation codes, see 2.5.4.
        /// </param>
        /// <param name="paramDesc">
        /// This value MUST be a null-terminated ASCII descriptor string. The server SHOULD validate that the ParamDesc
        /// value passed by the client matches what is specified by the RAPOpcode. The following table specifies the
        /// descriptor character and the notation for each data type.
        /// </param>
        /// <param name="dataDesc">
        /// (Optional) If this value is specified, it MUST be a null-terminated ASCII descriptor string that describes
        /// the contents of the data returned to the client. Certain RAPOpcodes specify a DataDesc field; for a list
        /// of Remote Administration Protocol commands that specify a DataDesc field, see section 2.5.5.
        /// </param>
        /// <param name="rapParamsAndAuxDesc">
        /// This field combines the following fields, because each of their length is unknown:<para/>
        /// RAPParams: Remote Administration Protocol command-specific parameters, as specified in sections 2.5.5, 2.5.6, 2.5.7,
        /// 2.5.8, and 2.5.9.<para/>
        /// AuxDesc: (Optional) If this value is specified, it MUST be a null-terminated ASCII descriptor string that describes
        /// auxiliary data returned to the client. If no AuxDesc field is specified for the Remote Administration
        /// Protocol command, this field MUST NOT be present. For the origin of the descriptor string values, see
        /// section 4.2.
        /// </param>
        /// <param name="rapInData">
        /// Additional data for the Remote Administration Protocol request. This field MUST be present in the
        /// NetPrintJobSetInfoRequest command. This field cannot be present in any other command.
        /// </param>
        /// <param name = "timeOut">
        /// The maximum amount of time in milliseconds to wait for the operation to complete. The client SHOULD set  
        /// this to 0 to indicate that no time-out is given. If the operation does not complete within the specified  
        /// time, the server MAY abort the request and send a failure response. 
        /// </param>
        /// <returns>a named rap request packet </returns>
        private SmbTransRapRequestPacket CreateTransNamedRapRequest(
            ushort messageId,
            ushort sessionUid,
            ushort treeId,
            SmbHeader_Flags_Values flags,
            SmbHeader_Flags2_Values flags2,
            TransSmbParametersFlags transactOptions,
            ushort rapOPCode,
            byte[] paramDesc,
            byte[] dataDesc,
            byte[] rapParamsAndAuxDesc,
            byte[] rapInData,
            uint timeOut)
        {
            SmbTransRapRequestPacket packet = new SmbTransRapRequestPacket();
            packet.SmbHeader = CifsMessageUtils.CreateSmbHeader(SmbCommand.SMB_COM_TRANSACTION,
                messageId, sessionUid, treeId, (SmbFlags)flags, (SmbFlags2)flags2);

            // Set Smb Parameters
            SMB_COM_TRANSACTION_Request_SMB_Parameters smbParameters =
                new SMB_COM_TRANSACTION_Request_SMB_Parameters();
            smbParameters.MaxParameterCount = this.capability.MaxParameterCount;
            smbParameters.MaxDataCount = this.capability.MaxDataCount;
            smbParameters.MaxSetupCount = this.capability.MaxSetupCount;
            smbParameters.Flags = transactOptions;
            smbParameters.Timeout = timeOut;
            smbParameters.SetupCount = 0; // the correct count in word of the Setup is always 0.
            smbParameters.Setup = new ushort[0];
            smbParameters.WordCount = (byte)(CifsMessageUtils.GetSize<SMB_COM_TRANSACTION_Request_SMB_Parameters>(
                smbParameters) / SmbCapability.NUM_BYTES_OF_WORD);

            // Set Smb Data
            SMB_COM_TRANSACTION_Request_SMB_Data smbData = new SMB_COM_TRANSACTION_Request_SMB_Data();
            smbData.Name = CifsMessageUtils.ToSmbStringBytes("", this.capability.IsUnicode);

            // Set Transaction Parameters
            TRANSACTION_Rap_Request_Trans_Parameters transParameters = new TRANSACTION_Rap_Request_Trans_Parameters();
            transParameters.RapOPCode = rapOPCode;
            transParameters.ParamDesc = paramDesc;
            transParameters.DataDesc = dataDesc;
            transParameters.RAPParamsAndAuxDesc = rapParamsAndAuxDesc;

            // Set Transaction Data
            TRANSACTION_Rap_Request_Trans_Data transData = new TRANSACTION_Rap_Request_Trans_Data();
            transData.RAPInData = rapInData;

            packet.SmbParameters = smbParameters;
            packet.SmbData = smbData;
            packet.TransParameters = transParameters;
            packet.TransData = transData;
            packet.UpdateCountAndOffset();

            // update TransactionSubCommand in SmbGlobalContext, record the transact action
            this.capability.TransactionSubCommand = TransSubCommandExtended.TRANS_EXT_RAP;

            return packet;
        }
        /// <summary>
        /// to decode the Trans parameters: from the general TransParameters to the concrete Trans Parameters. 
        /// </summary>
        protected override void DecodeTransParameters()
        {
            if (this.smbData.Trans_Parameters == null || this.smbData.Trans_Parameters.Length == 0)
            {
                return;
            }

            TRANSACTION_Rap_Request_Trans_Parameters param = new TRANSACTION_Rap_Request_Trans_Parameters();
            using (MemoryStream stream = new MemoryStream(this.smbData.Trans_Parameters))
            {
                using (Channel channel = new Channel(null, stream))
                {
                    param.RapOPCode = channel.Read<ushort>();
                    // the ParamDesc and DataDesc size
                    int descSize = this.smbData.Trans_Parameters.Length - SmbCapability.NUM_BYTES_OF_WORD;
                    if (descSize > 0)
                    {
                        byte[] descs = channel.ReadBytes(descSize);
                        int start = 0;
                        int index = 0;

                        // read the field ParamDesc.
                        if ((index = FindEndIndexOfAsciiString(descs, start)) != -1)
                        {
                            // move to the terminated descriptor.
                            index++;
                            // get the data
                            param.ParamDesc = ArrayUtility.SubArray<byte>(descs, start, index - start);
                            // update the start
                            start = index ;
                        }

                        // read the field DataDesc.
                        if ((index = FindEndIndexOfAsciiString(descs, start)) != -1)
                        {
                            // move to the terminated descriptor.
                            index++;
                            // get the data
                            param.DataDesc = ArrayUtility.SubArray<byte>(descs, start, index - start);
                            // update the start
                            start = index ;
                        }

                        // read the field RAPParamsAndAuxDesc.
                        if (descSize > start)
                        {
                            param.RAPParamsAndAuxDesc = ArrayUtility.SubArray<byte>(descs, start, descSize - start);
                        }
                    }
                }
            }
            this.transParameters = param;
        }