/// <summary>
        /// Deep copy constructor.
        /// </summary>
        public SmbTransRawWriteNmpipeRequestPacket(SmbTransRawWriteNmpipeRequestPacket packet)
            : base(packet)
        {
            this.InitDefaultValue();

            if (packet.transData.WriteData != null)
            {
                this.transData.WriteData = new byte[packet.transData.WriteData.Length];
                Array.Copy(packet.transData.WriteData, this.transData.WriteData, packet.transData.WriteData.Length);
            }
            else
            {
                this.transData.WriteData = new byte[0];
            }
        }
        /// <summary>
        /// Deep copy constructor.
        /// </summary>
        public SmbTransRawWriteNmpipeRequestPacket(SmbTransRawWriteNmpipeRequestPacket packet)
            : base(packet)
        {
            this.InitDefaultValue();

            if (packet.transData.WriteData != null)
            {
                this.transData.WriteData = new byte[packet.transData.WriteData.Length];
                Array.Copy(packet.transData.WriteData, this.transData.WriteData, packet.transData.WriteData.Length);
            }
            else
            {
                this.transData.WriteData = new byte[0];
            }
        }
        /// <summary>
        /// find the transaction packet.
        /// </summary>
        /// <param name="setupCount">the count of setup</param>
        /// <param name="command">the command of transaction packet</param>
        /// <returns>the target transaction packet</returns>
        private static SmbPacket FindTheTransactionPacket(byte setupCount, TransSubCommand command)
        {
            if (setupCount == 0)
            {
                return new SmbTransRapRequestPacket();
            }
            else if (setupCount == 3)
            {
                return new SmbTransMailslotWriteRequestPacket();
            }

            SmbPacket smbPacket = null;
            switch ((TransSubCommand)command)
            {
                case TransSubCommand.TRANS_SET_NMPIPE_STATE:
                    smbPacket = new SmbTransSetNmpipeStateRequestPacket();
                    break;
                case TransSubCommand.TRANS_QUERY_NMPIPE_STATE:
                    smbPacket = new SmbTransQueryNmpipeStateRequestPacket();
                    break;
                case TransSubCommand.TRANS_QUERY_NMPIPE_INFO:
                    smbPacket = new SmbTransQueryNmpipeInfoRequestPacket();
                    break;
                case TransSubCommand.TRANS_PEEK_NMPIPE:
                    smbPacket = new SmbTransPeekNmpipeRequestPacket();
                    break;
                case TransSubCommand.TRANS_TRANSACT_NMPIPE:
                    smbPacket = new SmbTransTransactNmpipeRequestPacket();
                    break;
                case TransSubCommand.TRANS_RAW_READ_NMPIPE:
                    smbPacket = new SmbTransRawReadNmpipeRequestPacket();
                    break;
                case TransSubCommand.TRANS_READ_NMPIPE:
                    smbPacket = new SmbTransReadNmpipeRequestPacket();
                    break;
                case TransSubCommand.TRANS_WRITE_NMPIPE:
                    smbPacket = new SmbTransWriteNmpipeRequestPacket();
                    break;
                case TransSubCommand.TRANS_WAIT_NMPIPE:
                    smbPacket = new SmbTransWaitNmpipeRequestPacket();
                    break;
                case TransSubCommand.TRANS_CALL_NMPIPE:
                    smbPacket = new SmbTransCallNmpipeRequestPacket();
                    break;
                case TransSubCommand.TRANS_RAW_WRITE_NMPIPE:
                    smbPacket = new SmbTransRawWriteNmpipeRequestPacket();
                    break;
                default:
                    break;
            }
            return smbPacket;
        }
        /// <summary>
        /// to create a TransRawWriteNmpipe request packet.
        /// </summary>
        /// <param name="messageId">This field SHOULD be the multiplex ID that is used to associate a response with a
        /// request.</param>
        /// <param name="uid">This field SHOULD identify the authenticated instance of the user.</param>
        /// <param name="treeId">This field identifies the subdirectory (or tree) on the server that the client is
        /// accessing.</param>
        /// <param name="flags">An 8-bit field of 1-bit flags describing various features in effect for the
        /// message</param>
        /// <param name="flags2">A 16-bit field of 1-bit flags that represent various features in effect for the
        /// message. Unspecified bits are reserved and MUST be zero.</param>
        /// <param name="maxParameterCount">The maximum number of parameter bytes that the client will accept in the
        /// transaction reply. The server MUST NOT return more than this number of parameter bytes.</param>
        /// <param name="maxDataCount">The maximum number of data bytes that the client will accept in the transaction
        /// reply. The server MUST NOT return more than this number of data bytes.</param>
        /// <param name="maxSetupCount">Maximum number of setup bytes that the client will accept in the transaction
        /// reply. The server MUST NOT return more than this number of setup bytes</param>
        /// <param name="smbParametersflags">A set of bit flags that alter the behavior of the requested
        /// operation</param>
        /// <param name="timeout">The value of this field MUST be the maximum number of milliseconds the server SHOULD
        /// wait for completion of the transaction before generating a timeout and returning a response to the
        /// client. </param>
        /// <param name="fid">MUST contain a valid FID obtained from a previously successful SMB open command.</param>
        /// <param name="writeData">This field MUST contain the bytes to be written to the named pipe as part of the
        /// transacted operation.</param>
        /// <param name="name">The pathname of the mailslot or named pipe to which the transaction subcommand applies
        /// or a client supplied identifier that provides a name for the transaction.</param>
        /// <returns>a TransRawWriteNmpipe request packet</returns>
        public SmbTransRawWriteNmpipeRequestPacket CreateTransRawWriteNmpipeRequest(
            ushort messageId,
            ushort uid,
            ushort treeId,
            SmbFlags flags,
            SmbFlags2 flags2,
            ushort maxParameterCount,
            ushort maxDataCount,
            byte maxSetupCount,
            TransSmbParametersFlags smbParametersflags,
            uint timeout,
            ushort fid,
            byte[] writeData,
            string name)
        {
            if (writeData == null)
            {
                writeData = new byte[0];
            }
            if (name == null)
            {
                name = string.Empty;
            }

            SmbTransRawWriteNmpipeRequestPacket packet = new SmbTransRawWriteNmpipeRequestPacket();
            packet.SmbHeader = CifsMessageUtils.CreateSmbHeader(SmbCommand.SMB_COM_TRANSACTION,
                messageId, uid, treeId, flags, flags2);

            // Set Smb Parameters
            SMB_COM_TRANSACTION_Request_SMB_Parameters smbParameters =
                new SMB_COM_TRANSACTION_Request_SMB_Parameters();
            smbParameters.MaxParameterCount = maxParameterCount;
            smbParameters.MaxDataCount = maxDataCount;
            smbParameters.MaxSetupCount = maxSetupCount;
            smbParameters.Flags = smbParametersflags;
            smbParameters.Timeout = timeout;
            smbParameters.SetupCount = 2; // the correct count in word of the Setup is always 2.
            smbParameters.Setup = new ushort[2];
            smbParameters.Setup[0] = (ushort)TransSubCommand.TRANS_RAW_WRITE_NMPIPE;
            smbParameters.Setup[1] = fid;
            smbParameters.WordCount = (byte)(CifsMessageUtils.GetSize<SMB_COM_TRANSACTION_Request_SMB_Parameters>(
                smbParameters) / NumBytesOfWord);

            // Set Smb Data
            SMB_COM_TRANSACTION_Request_SMB_Data smbData = new SMB_COM_TRANSACTION_Request_SMB_Data();
            smbData.Name = CifsMessageUtils.ToSmbStringBytes(name,
                (flags2 & SmbFlags2.SMB_FLAGS2_UNICODE) == SmbFlags2.SMB_FLAGS2_UNICODE);

            // Set Trans_Data
            TRANS_RAW_WRITE_NMPIPE_Request_Trans_Data transData = new TRANS_RAW_WRITE_NMPIPE_Request_Trans_Data();
            transData.WriteData = writeData;

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

            return packet;
        }
        public SmbTransRawWriteNmpipeSuccessResponsePacket CreateTransRawWriteNmpipeSuccessResponse(
            CifsServerPerConnection connection,
            SmbTransRawWriteNmpipeRequestPacket request)
        {
            SmbTransRawWriteNmpipeSuccessResponsePacket response = new SmbTransRawWriteNmpipeSuccessResponsePacket();
            response.SmbHeader = CifsMessageUtils.CreateSmbHeader(connection, request);

            TRANS_RAW_WRITE_NMPIPE_Response_Trans_Parameters transParameters = response.TransParameters;
            transParameters.BytesWritten = (ushort)request.TransData.WriteData.Length;

            response.UpdateCountAndOffset();

            return response;
        }