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

            this.smbParameters.WordCount          = packet.SmbParameters.WordCount;
            this.smbParameters.FID                = packet.SmbParameters.FID;
            this.smbParameters.CountOfBytesToRead = packet.SmbParameters.CountOfBytesToRead;
            this.smbParameters.ReadOffsetInBytes  = packet.SmbParameters.ReadOffsetInBytes;
            this.smbParameters.EstimateOfRemainingBytesToBeRead =
                packet.smbParameters.EstimateOfRemainingBytesToBeRead;

            this.smbData.ByteCount = packet.SmbData.ByteCount;
        }
        /// <summary>
        /// Deep copy constructor.
        /// </summary>
        public SmbReadRequestPacket(SmbReadRequestPacket packet)
            : base(packet)
        {
            this.InitDefaultValue();

            this.smbParameters.WordCount = packet.SmbParameters.WordCount;
            this.smbParameters.FID = packet.SmbParameters.FID;
            this.smbParameters.CountOfBytesToRead = packet.SmbParameters.CountOfBytesToRead;
            this.smbParameters.ReadOffsetInBytes = packet.SmbParameters.ReadOffsetInBytes;
            this.smbParameters.EstimateOfRemainingBytesToBeRead =
                packet.smbParameters.EstimateOfRemainingBytesToBeRead;

            this.smbData.ByteCount = packet.SmbData.ByteCount;
        }
        /// <summary>
        /// to create a Read 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 from which the data
        /// MUST be read.</param>
        /// <param name="countOfBytesToRead">This field is a 16-bit unsigned integer indicating the number of bytes to
        /// be read from the file. The client MUST ensure that the amount of data requested will fit in the negotiated
        /// maximum buffer size</param>
        /// <param name="readOffsetInBytes">This field is a 32-bit unsigned integer indicating the offset in number of
        /// bytes from which to begin reading from the file. The client MUST ensure that the amount of data requested
        /// fits 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="estimateOfRemainingBytesToBeRead">This field is a 16-bit unsigned integer indicating the
        /// remaining number of bytes that the client intends to read from the file. This is an advisory field and MAY
        /// be zero</param>
        /// <returns>a Read request packet</returns>
        public SmbReadRequestPacket CreateReadRequest(
            ushort messageId,
            ushort uid,
            ushort treeId,
            SmbFlags flags,
            SmbFlags2 flags2,
            ushort fid,
            ushort countOfBytesToRead,
            uint readOffsetInBytes,
            ushort estimateOfRemainingBytesToBeRead)
        {
            SmbReadRequestPacket packet = new SmbReadRequestPacket();

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

            SMB_COM_READ_Request_SMB_Parameters smbParameters = new SMB_COM_READ_Request_SMB_Parameters();
            smbParameters.FID = fid;
            smbParameters.CountOfBytesToRead = countOfBytesToRead;
            smbParameters.ReadOffsetInBytes = readOffsetInBytes;
            smbParameters.EstimateOfRemainingBytesToBeRead = estimateOfRemainingBytesToBeRead;
            smbParameters.WordCount = (byte)(Marshal.SizeOf(smbParameters) / NumBytesOfWord);

            SMB_COM_READ_Request_SMB_Data smbData = new SMB_COM_READ_Request_SMB_Data();
            smbData.ByteCount = 0;

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

            return packet;
        }
        public SmbReadResponsePacket CreateReadResponse(
            CifsServerPerConnection connection,
            SmbReadRequestPacket request,
            byte[] bytes)
        {
            bytes = bytes ?? new byte[0];
            SmbReadResponsePacket response = new SmbReadResponsePacket();
            response.SmbHeader = CifsMessageUtils.CreateSmbHeader(connection, request);

            SMB_COM_READ_Response_SMB_Parameters smbParameters = response.SmbParameters;
            smbParameters.CountOfBytesReturned = (ushort)bytes.Length;
            smbParameters.Reserved = new ushort[4];
            smbParameters.WordCount = (byte)(TypeMarshal.GetBlockMemorySize(smbParameters) / 2);
            response.SmbParameters = smbParameters;

            SMB_COM_READ_Response_SMB_Data smbData = response.SmbData;
            smbData.ByteCount = (ushort)(Marshal.SizeOf(response.SmbData.BufferFormat) + Marshal.SizeOf(
                    response.SmbData.CountOfBytesRead) + bytes.Length);
            smbData.CountOfBytesRead = (ushort)bytes.Length;
            smbData.BufferFormat = 0x01;
            smbData.Bytes = bytes;
            response.SmbData = smbData;

            return response;
        }