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

            this.smbParameters.WordCount = packet.SmbParameters.WordCount;
            this.smbParameters.FID       = packet.SmbParameters.FID;
            this.smbParameters.Offset    = packet.SmbParameters.Offset;
            this.smbParameters.MaxCountOfBytesToReturn = packet.SmbParameters.MaxCountOfBytesToReturn;
            this.smbParameters.MinCountOfBytesToReturn = packet.SmbParameters.MinCountOfBytesToReturn;
            this.smbParameters.Timeout  = packet.SmbParameters.Timeout;
            this.smbParameters.Reserved = packet.SmbParameters.Reserved;

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

            this.smbParameters.WordCount = packet.SmbParameters.WordCount;
            this.smbParameters.FID = packet.SmbParameters.FID;
            this.smbParameters.Offset = packet.SmbParameters.Offset;
            this.smbParameters.MaxCountOfBytesToReturn = packet.SmbParameters.MaxCountOfBytesToReturn;
            this.smbParameters.MinCountOfBytesToReturn = packet.SmbParameters.MinCountOfBytesToReturn;
            this.smbParameters.Timeout = packet.SmbParameters.Timeout;
            this.smbParameters.Reserved = packet.SmbParameters.Reserved;

            this.smbData.ByteCount = packet.SmbData.ByteCount;
        }
        /// <summary>
        /// to create a ReadMpx 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="offset">The offset in bytes from the start of the file at which the read MUST begin. This is
        /// the lower 32 bits of a 64 bit value if the WordCount is 10</param>
        /// <param name="maxCountOfBytesToReturn">The requested maximum number of bytes to read from the file and
        /// return to the client. The value MAY exceed the negotiated buffer size</param>
        /// <param name="minCountOfBytesToReturn">The requested minimum number of bytes to read from the file and
        /// return to the client. This field is used only when reading from a named pipe or a device. It is ignored when
        /// reading from a standard file</param>
        /// <param name="timeout">Support for this field is optional and this field is used only when reading from a
        /// named pipe or i/o device.</param>
        /// <returns>a ReadMpx request packet</returns>
        public SmbReadMpxRequestPacket CreateReadMpxRequest(
            ushort messageId,
            ushort uid,
            ushort treeId,
            SmbFlags flags,
            SmbFlags2 flags2,
            ushort fid,
            uint offset,
            ushort maxCountOfBytesToReturn,
            ushort minCountOfBytesToReturn,
            uint timeout)
        {
            SmbReadMpxRequestPacket packet = new SmbReadMpxRequestPacket();

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

            SMB_COM_READ_MPX_Request_SMB_Parameters smbParameters = new SMB_COM_READ_MPX_Request_SMB_Parameters();
            smbParameters.FID = fid;
            smbParameters.Offset = offset;
            smbParameters.MaxCountOfBytesToReturn = maxCountOfBytesToReturn;
            smbParameters.MinCountOfBytesToReturn = minCountOfBytesToReturn;
            smbParameters.Timeout = timeout;
            smbParameters.Reserved = 0;
            smbParameters.WordCount = (byte)(Marshal.SizeOf(smbParameters) / NumBytesOfWord);

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

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

            return packet;
        }
        public SmbReadMpxResponsePacket CreateReadMpxResponse(
            CifsServerPerConnection connection,
            SmbReadMpxRequestPacket request,
            ushort offset,
            ushort count,
            ushort remaining,
            byte[] data)
        {
            data = data ?? new byte[0];
            SmbReadMpxResponsePacket response = new SmbReadMpxResponsePacket();
            response.SmbHeader = CifsMessageUtils.CreateSmbHeader(connection, request);

            int padOffset = Marshal.SizeOf(response.SmbParameters) + sizeof(ushort);
            SMB_COM_READ_MPX_Response_SMB_Parameters smbParameters = response.SmbParameters;
            smbParameters.Offset = offset;
            smbParameters.Count = count;
            smbParameters.Remaining = remaining;
            smbParameters.DataCompactionMode = 0x0000;
            smbParameters.Reserved = 0x0000;
            smbParameters.DataLength = (ushort)data.Length;
            smbParameters.DataOffset = (ushort)((padOffset + 3) & ~3);
            smbParameters.WordCount = (byte)(TypeMarshal.GetBlockMemorySize(smbParameters) / 2);
            response.SmbParameters = smbParameters;

            SMB_COM_READ_MPX_Response_SMB_Data smbData = response.SmbData;
            smbData.Pad = new byte[response.SmbParameters.DataOffset - padOffset];
            smbData.Data = data;
            smbData.ByteCount = (ushort)(response.SmbParameters.DataOffset + data.Length);
            response.SmbData = smbData;

            return response;
        }