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

            this.smbParameters.WordCount = packet.SmbParameters.WordCount;
            this.smbParameters.FID = packet.SmbParameters.FID;
            this.smbParameters.CountOfBytesToWrite = packet.SmbParameters.CountOfBytesToWrite;
            this.smbParameters.WriteOffsetInBytes = packet.SmbParameters.WriteOffsetInBytes;
            this.smbParameters.EstimateOfRemainingBytesToBeWritten =
                packet.smbParameters.EstimateOfRemainingBytesToBeWritten;

            this.smbData.ByteCount = packet.SmbData.ByteCount;
            this.smbData.BufferFormat = packet.SmbData.BufferFormat;
            this.smbData.DataLength = packet.SmbData.DataLength;
            if (packet.smbData.Data != null)
            {
                this.smbData.Data = new byte[packet.smbData.Data.Length];
                Array.Copy(packet.smbData.Data, this.smbData.Data, packet.smbData.Data.Length);
            }
            else
            {
                this.smbData.Data = new byte[0];
            }
        }
        /// <summary>
        /// Deep copy constructor.
        /// </summary>
        public SmbWriteAndUnlockRequestPacket(SmbWriteAndUnlockRequestPacket packet)
            : base(packet)
        {
            this.InitDefaultValue();

            this.smbParameters.WordCount           = packet.SmbParameters.WordCount;
            this.smbParameters.FID                 = packet.SmbParameters.FID;
            this.smbParameters.CountOfBytesToWrite = packet.SmbParameters.CountOfBytesToWrite;
            this.smbParameters.WriteOffsetInBytes  = packet.SmbParameters.WriteOffsetInBytes;
            this.smbParameters.EstimateOfRemainingBytesToBeWritten =
                packet.smbParameters.EstimateOfRemainingBytesToBeWritten;

            this.smbData.ByteCount    = packet.SmbData.ByteCount;
            this.smbData.BufferFormat = packet.SmbData.BufferFormat;
            this.smbData.DataLength   = packet.SmbData.DataLength;
            if (packet.smbData.Data != null)
            {
                this.smbData.Data = new byte[packet.smbData.Data.Length];
                Array.Copy(packet.smbData.Data, this.smbData.Data, packet.smbData.Data.Length);
            }
            else
            {
                this.smbData.Data = new byte[0];
            }
        }
        /// <summary>
        /// to create a WriteAndUnlock 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="fid">This field MUST be a valid 16-bit signed integer indicating the file to which the data
        /// MUST be written</param>
        /// <param name="writeOffsetInBytes">This field is a 32-bit unsigned integer indicating the offset in number of
        /// bytes from the beginning of the file at which to begin writing to the file. The client MUST ensure that the
        /// amount of data sent can fit in the negotiated maximum buffer size. Because this field is limited to 32-bits
        /// this command is inappropriate for files having 64-bit offsets.</param>
        /// <param name="estimateOfRemainingBytesToBeWritten">This field is a 16-bit unsigned integer indicating the
        /// remaining number of bytes the client anticipates to write to the file. This is an advisory field and MAY be
        /// zero. This information can be used by the server to optimize cache behavior.</param>
        /// <param name="data">The raw bytes to be written to the file</param>
        /// <returns> a WriteAndUnlock request packet</returns>
        public SmbWriteAndUnlockRequestPacket CreateWriteAndUnlockRequest(
            ushort messageId,
            ushort uid,
            ushort treeId,
            SmbFlags flags,
            SmbFlags2 flags2,
            ushort fid,
            uint writeOffsetInBytes,
            ushort estimateOfRemainingBytesToBeWritten,
            byte[] data)
        {
            if (data == null)
            {
                data = new byte[0];
            }

            SmbWriteAndUnlockRequestPacket packet = new SmbWriteAndUnlockRequestPacket();

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

            SMB_COM_WRITE_AND_UNLOCK_Request_SMB_Parameters smbParameters =
                new SMB_COM_WRITE_AND_UNLOCK_Request_SMB_Parameters();
            smbParameters.FID = fid;
            smbParameters.CountOfBytesToWrite = (ushort)data.Length;
            smbParameters.WriteOffsetInBytes = writeOffsetInBytes;
            smbParameters.EstimateOfRemainingBytesToBeWritten = estimateOfRemainingBytesToBeWritten;
            smbParameters.WordCount = (byte)(Marshal.SizeOf(smbParameters) / NumBytesOfWord);

            SMB_COM_WRITE_AND_UNLOCK_Request_SMB_Data smbData = new SMB_COM_WRITE_AND_UNLOCK_Request_SMB_Data();
            smbData.BufferFormat = (byte)DataBufferFormat.DataBuffer;
            smbData.DataLength = (ushort)data.Length;
            smbData.Data = data;
            smbData.ByteCount = (ushort)(Marshal.SizeOf(smbData.BufferFormat) + Marshal.SizeOf(smbData.DataLength)
                + smbData.DataLength);

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

            return packet;
        }
        public SmbWriteAndUnlockResponsePacket CreateWriteAndUnlockResponse(
            CifsServerPerConnection connection,
            SmbWriteAndUnlockRequestPacket request)
        {
            SmbWriteAndUnlockResponsePacket response = new SmbWriteAndUnlockResponsePacket();
            response.SmbHeader = CifsMessageUtils.CreateSmbHeader(connection, request);

            SMB_COM_WRITE_AND_UNLOCK_Response_SMB_Parameters smbParameters = response.SmbParameters;
            smbParameters.CountOfBytesWritten = request.SmbParameters.CountOfBytesToWrite;
            smbParameters.WordCount = (byte)(TypeMarshal.GetBlockMemorySize(smbParameters) / 2);
            response.SmbParameters = smbParameters;

            return response;
        }