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

            this.smbParameters.WordCount        = packet.SmbParameters.WordCount;
            this.smbParameters.MaxCount         = packet.SmbParameters.MaxCount;
            this.smbParameters.SearchAttributes = packet.SmbParameters.SearchAttributes;

            this.smbData.ByteCount     = packet.SmbData.ByteCount;
            this.smbData.BufferFormat1 = packet.SmbData.BufferFormat1;

            if (packet.smbData.FileName != null)
            {
                this.smbData.FileName = new byte[packet.smbData.FileName.Length];
                Array.Copy(packet.smbData.FileName, this.smbData.FileName, packet.smbData.FileName.Length);
            }
            else
            {
                this.smbData.FileName = new byte[0];
            }
            this.smbData.BufferFormat2   = packet.SmbData.BufferFormat2;
            this.smbData.ResumeKeyLength = packet.SmbData.ResumeKeyLength;
            this.smbData.ResumeKey       = new SMB_Resume_Key[packet.smbData.ResumeKeyLength];

            if (packet.smbData.ResumeKey != null)
            {
                Array.Copy(packet.smbData.ResumeKey, this.smbData.ResumeKey, packet.smbData.ResumeKeyLength);
            }
            else
            {
                this.smbData.ResumeKey = new SMB_Resume_Key[0];
            }
        }
        /// <summary>
        /// Deep copy constructor.
        /// </summary>
        public SmbFindUniqueRequestPacket(SmbFindUniqueRequestPacket packet)
            : base(packet)
        {
            this.InitDefaultValue();

            this.smbParameters.WordCount = packet.SmbParameters.WordCount;
            this.smbParameters.MaxCount = packet.SmbParameters.MaxCount;
            this.smbParameters.SearchAttributes = packet.SmbParameters.SearchAttributes;

            this.smbData.ByteCount = packet.SmbData.ByteCount;
            this.smbData.BufferFormat1 = packet.SmbData.BufferFormat1;

            if (packet.smbData.FileName != null)
            {
                this.smbData.FileName = new byte[packet.smbData.FileName.Length];
                Array.Copy(packet.smbData.FileName, this.smbData.FileName, packet.smbData.FileName.Length);
            }
            else
            {
                this.smbData.FileName = new byte[0];
            }
            this.smbData.BufferFormat2 = packet.SmbData.BufferFormat2;
            this.smbData.ResumeKeyLength = packet.SmbData.ResumeKeyLength;
            this.smbData.ResumeKey = new SMB_Resume_Key[packet.smbData.ResumeKeyLength];

            if (packet.smbData.ResumeKey != null)
            {
                Array.Copy(packet.smbData.ResumeKey, this.smbData.ResumeKey, packet.smbData.ResumeKeyLength);
            }
            else
            {
                this.smbData.ResumeKey = new SMB_Resume_Key[0];
            }
        }
        /// <summary>
        /// to create a FindUnique 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="maxCount">The maximum number of directory entries to return</param>
        /// <param name="searchAttributes">ATTRIBUTES  An attribute mask used to specify the standard attributes a file
        /// MUST have in order to match the search</param>
        /// <param name="fileName">null-terminated SMB_STRING. This is the full directory path (relative to the TID) of
        /// the file(s) being sought</param>
        /// <param name="resumeKey">The ResumeKey contains data used by both the client and the server to maintain the
        /// state of the search</param>
        /// <returns>a FindUnique request packet</returns>
        public SmbFindUniqueRequestPacket CreateFindUniqueRequest(
            ushort messageId,
            ushort uid,
            ushort treeId,
            SmbFlags flags,
            SmbFlags2 flags2,
            ushort maxCount,
            SmbFileAttributes searchAttributes,
            string fileName,
            SMB_Resume_Key[] resumeKey)
        {
            if (fileName == null)
            {
                fileName = string.Empty;
            }
            if (resumeKey == null)
            {
                resumeKey = new SMB_Resume_Key[0];
            }

            SmbFindUniqueRequestPacket packet = new SmbFindUniqueRequestPacket();

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

            SMB_COM_FIND_UNIQUE_Request_SMB_Parameters smbParameters =
                new SMB_COM_FIND_UNIQUE_Request_SMB_Parameters();
            smbParameters.MaxCount = maxCount;
            smbParameters.SearchAttributes = searchAttributes;
            smbParameters.WordCount = (byte)(Marshal.SizeOf(smbParameters) / NumBytesOfWord);

            SMB_COM_FIND_UNIQUE_Request_SMB_Data smbData = new SMB_COM_FIND_UNIQUE_Request_SMB_Data();
            int resumeKeySize = 0;
            if (resumeKey.Length > 0)
            {
                resumeKeySize = CifsMessageUtils.GetSize<SMB_Resume_Key>(resumeKey[0]);
            }
            smbData.BufferFormat1 = (byte)DataBufferFormat.SmbString;
            smbData.FileName = CifsMessageUtils.ToSmbStringBytes(fileName,
                (flags2 & SmbFlags2.SMB_FLAGS2_UNICODE) == SmbFlags2.SMB_FLAGS2_UNICODE);
            smbData.BufferFormat2 = (byte)DataBufferFormat.VariableBlock;
            smbData.ResumeKeyLength = (ushort)resumeKeySize;
            smbData.ResumeKey = resumeKey;
            smbData.ByteCount = (ushort)(Marshal.SizeOf(smbData.BufferFormat1) + smbData.FileName.Length
                + Marshal.SizeOf(smbData.BufferFormat2) + Marshal.SizeOf(smbData.ResumeKeyLength)
                + smbData.ResumeKeyLength);

            packet.SmbParameters = smbParameters;
            packet.SmbData = smbData;

            return packet;
        }
        public SmbFindUniqueResponsePacket CreateFindUniqueResponse(
            CifsServerPerConnection connection,
            SmbFindUniqueRequestPacket request,
            SMB_Directory_Information[] directoryInformationData)
        {
            directoryInformationData = directoryInformationData ?? new SMB_Directory_Information[0];
            SmbFindUniqueResponsePacket response = new SmbFindUniqueResponsePacket();
            response.SmbHeader = CifsMessageUtils.CreateSmbHeader(connection, request);

            SMB_COM_FIND_UNIQUE_Response_SMB_Parameters smbParameters = response.SmbParameters;
            smbParameters.Count = (ushort)directoryInformationData.Length;
            smbParameters.WordCount = (byte)(TypeMarshal.GetBlockMemorySize(smbParameters) / 2);
            response.SmbParameters = smbParameters;

            ushort dataLength = 0;
            foreach (SMB_Directory_Information info in directoryInformationData)
            {
                dataLength += (ushort)TypeMarshal.GetBlockMemorySize(info);
            }
            SMB_COM_FIND_UNIQUE_Response_SMB_Data smbData = response.SmbData;
            smbData.BufferFormat = 0x05;
            smbData.DirectoryInformationData = directoryInformationData;
            smbData.DataLength = dataLength;
            smbData.ByteCount = (ushort)(dataLength + 0x03);
            response.SmbData = smbData;

            return response;
        }