/// <summary>
        /// Decode the payload for type of Referral Entry V3V4_NonNameListReferral
        /// </summary>
        /// <param name="channel">channel with payload data</param>
        /// <exception cref=" System.InvalidOperationException">
        /// Fail to decode payload data to ReferralV3V4_NonNameListReferral structure
        /// </exception>
        private void DecodeReferralV3V4_NonNameListReferral(Channel channel)
        {
            bool isDfsPathFollowed = false;
            List<DFS_REFERRAL_V3V4_NonNameListReferral> tempList = new List<DFS_REFERRAL_V3V4_NonNameListReferral>();

            for (int i = 0; i < this.referralResponse.NumberOfReferrals; i++)
            {
                DFS_REFERRAL_V3V4_NonNameListReferral referral3 = new DFS_REFERRAL_V3V4_NonNameListReferral();

                // Read the fixed portion of DFS_REFERRAL_V3V4_NonNameListReferral
                referral3.VersionNumber = channel.Read<ushort>();
                referral3.Size = channel.Read<ushort>();
                referral3.ServerType = channel.Read<ushort>();
                referral3.ReferralEntryFlags = channel.Read<ReferralEntryFlags_Values>();
                referral3.TimeToLive = channel.Read<uint>();
                referral3.DFSPathOffset = channel.Read<ushort>();
                referral3.DFSAlternatePathOffset = channel.Read<ushort>();
                referral3.NetworkAddressOffset = channel.Read<ushort>();
                referral3.ServiceSiteGuid = new Guid(channel.ReadBytes(16));

                if (i == 0 && referral3.DFSPathOffset == referral3.Size)
                {
                    isDfsPathFollowed = true;
                }

                // The Dfs paths of immediately follows each referral entry. Read the paths orderly.
                if (isDfsPathFollowed)
                {
                    // Get the Dfs paths from channel
                    // TD does not mention whether padding data exists between Dfs paths.
                    // Drop the possibly exists padding data
                    referral3.DFSPath = ReadDfsPath(channel);
                    ReadPadding(channel, referral3.DFSAlternatePathOffset - referral3.DFSPathOffset
                        - (referral3.DFSPath.Length + 1) * sizeofWord);

                    referral3.DFSAlternatePath = ReadDfsPath(channel);
                    ReadPadding(channel, referral3.NetworkAddressOffset - referral3.DFSAlternatePathOffset
                        - (referral3.DFSAlternatePath.Length + 1) * sizeofWord);

                    referral3.DFSTargetPath = ReadDfsPath(channel);
                }
                tempList.Add(referral3);
            }

            // All Dfs paths follow the last referral entry.Read the paths after all entries have been read.
            if (!isDfsPathFollowed)
            {
                ushort referralFixedSize = tempList[0].Size;
                byte[] pathData = channel.ReadBytes((int)(channel.Stream.Length - channel.Stream.Position));

                for (int i = 0; i < tempList.Count; i++)
                {
                    // Calculate the offsets of Dfs paths
                    int leftCount = tempList.Count - i;
                    DFS_REFERRAL_V3V4_NonNameListReferral referral3 = tempList[i];
                    int dfsPathOffset = referral3.DFSPathOffset - leftCount * referralFixedSize;
                    int dfsAlternatePathOffset = referral3.DFSAlternatePathOffset -
                        leftCount * referralFixedSize;
                    int targetPathOffset = referral3.NetworkAddressOffset - leftCount * referralFixedSize;

                    // Get the Dfs paths
                    referral3.DFSPath = ReadDfsPath(pathData, dfsPathOffset);
                    referral3.DFSAlternatePath = ReadDfsPath(pathData, dfsAlternatePathOffset);
                    referral3.DFSTargetPath = ReadDfsPath(pathData, targetPathOffset);

                    tempList[i] = referral3;
                }
            }
            this.referralResponse.ReferralEntries = tempList.ToArray();
        }
        /// <summary>
        /// Decode the payload for type of Referral Entry V3V4_NonNameListReferral
        /// </summary>
        /// <param name="channel">channel with payload data</param>
        /// <exception cref=" System.InvalidOperationException">
        /// Fail to decode payload data to ReferralV3V4_NonNameListReferral structure
        /// </exception>
        private void DecodeReferralV3V4_NonNameListReferral(Channel channel)
        {
            bool isDfsPathFollowed = false;
            List <DFS_REFERRAL_V3V4_NonNameListReferral> tempList = new List <DFS_REFERRAL_V3V4_NonNameListReferral>();

            for (int i = 0; i < this.referralResponse.NumberOfReferrals; i++)
            {
                DFS_REFERRAL_V3V4_NonNameListReferral referral3 = new DFS_REFERRAL_V3V4_NonNameListReferral();

                // Read the fixed portion of DFS_REFERRAL_V3V4_NonNameListReferral
                referral3.VersionNumber          = channel.Read <ushort>();
                referral3.Size                   = channel.Read <ushort>();
                referral3.ServerType             = channel.Read <ushort>();
                referral3.ReferralEntryFlags     = channel.Read <ReferralEntryFlags_Values>();
                referral3.TimeToLive             = channel.Read <uint>();
                referral3.DFSPathOffset          = channel.Read <ushort>();
                referral3.DFSAlternatePathOffset = channel.Read <ushort>();
                referral3.NetworkAddressOffset   = channel.Read <ushort>();
                referral3.ServiceSiteGuid        = new Guid(channel.ReadBytes(16));

                if (i == 0 && referral3.DFSPathOffset == referral3.Size)
                {
                    isDfsPathFollowed = true;
                }

                // The Dfs paths of immediately follows each referral entry. Read the paths orderly.
                if (isDfsPathFollowed)
                {
                    // Get the Dfs paths from channel
                    // TD does not mention whether padding data exists between Dfs paths.
                    // Drop the possibly exists padding data
                    referral3.DFSPath = ReadDfsPath(channel);
                    ReadPadding(channel, referral3.DFSAlternatePathOffset - referral3.DFSPathOffset
                                - (referral3.DFSPath.Length + 1) * sizeofWord);

                    referral3.DFSAlternatePath = ReadDfsPath(channel);
                    ReadPadding(channel, referral3.NetworkAddressOffset - referral3.DFSAlternatePathOffset
                                - (referral3.DFSAlternatePath.Length + 1) * sizeofWord);

                    referral3.DFSTargetPath = ReadDfsPath(channel);
                }
                tempList.Add(referral3);
            }

            // All Dfs paths follow the last referral entry.Read the paths after all entries have been read.
            if (!isDfsPathFollowed)
            {
                ushort referralFixedSize = tempList[0].Size;
                byte[] pathData          = channel.ReadBytes((int)(channel.Stream.Length - channel.Stream.Position));

                for (int i = 0; i < tempList.Count; i++)
                {
                    // Calculate the offsets of Dfs paths
                    int leftCount = tempList.Count - i;
                    DFS_REFERRAL_V3V4_NonNameListReferral referral3 = tempList[i];
                    int dfsPathOffset          = referral3.DFSPathOffset - leftCount * referralFixedSize;
                    int dfsAlternatePathOffset = referral3.DFSAlternatePathOffset -
                                                 leftCount * referralFixedSize;
                    int targetPathOffset = referral3.NetworkAddressOffset - leftCount * referralFixedSize;

                    // Get the Dfs paths
                    referral3.DFSPath          = ReadDfsPath(pathData, dfsPathOffset);
                    referral3.DFSAlternatePath = ReadDfsPath(pathData, dfsAlternatePathOffset);
                    referral3.DFSTargetPath    = ReadDfsPath(pathData, targetPathOffset);

                    tempList[i] = referral3;
                }
            }
            this.referralResponse.ReferralEntries = tempList.ToArray();
        }