Microsoft.Protocols.TestTools.StackSdk.BranchCache.Pchc.DecodeMessage.DecodeSegmentInfoMessage C# (CSharp) Method

DecodeSegmentInfoMessage() public static method

Unmarshal the segment info message.
public static DecodeSegmentInfoMessage ( byte byteArr ) : SEGMENT_INFO_MESSAGE
byteArr byte The payload.
return SEGMENT_INFO_MESSAGE
        public static SEGMENT_INFO_MESSAGE DecodeSegmentInfoMessage(byte[] byteArr)
        {
            int index = 0;
            byte[] informationData = GetBytes(byteArr, ref index, byteArr.Length - index);
            int tempIndex = 0;
            SEGMENT_INFO_MESSAGE segmentInfoMessage;

            MESSAGE_HEADER msgHeader;
            msgHeader.MinorVersion = informationData[tempIndex++];
            msgHeader.MajorVersion = informationData[tempIndex++];
            msgHeader.MsgType = (PCHC_MESSAGE_TYPE)GetUInt16(informationData, ref tempIndex, false);
            msgHeader.Padding = GetBytes(informationData, ref tempIndex, 4);
            segmentInfoMessage.MsgHeader = msgHeader;

            CONNECTION_INFORMATION connectionInfo;
            connectionInfo.Port = GetUInt16(informationData, ref tempIndex, false);
            connectionInfo.Padding = GetBytes(informationData, ref tempIndex, 6);
            segmentInfoMessage.ConnectionInfo = connectionInfo;

            segmentInfoMessage.ContentTag = GetBytes(informationData, ref tempIndex, 16);
            segmentInfoMessage.SegmentInfo = PccrcUtility.ParseContentInformation(informationData, ref tempIndex);

            return segmentInfoMessage;
        }

Usage Example

Beispiel #1
0
        /// <summary>
        /// Expect the SEGMENT_INFO_MESSAGE request from the client.
        /// </summary>
        /// <param name="ipaddress">The expected ipAddress of the remote endpoint which send request.</param>
        /// <param name="timeout">The waiting timeout.</param>
        /// <returns>Return the SEGMENT_INFO_MESSAGE received.</returns>
        /// <exception cref="NoSEGMENTINFOMESSAGEReceivedException">
        /// Throw when no SEGMENT_INFO_MESSAGE request from the client.
        /// </exception>
        public SEGMENT_INFO_MESSAGE ExpectSegmentInfoMessage(string ipaddress, TimeSpan timeout)
        {
            // Make sure the timeout is not less than 1000 milliseconds.
            if (timeout.TotalMilliseconds < 1000)
            {
                if (this.logger != null)
                {
                    this.logger.AddWarning(string.Format(
                                               "The timeout total milliseconds: {0} from the param \"timeout\" is too small.",
                                               timeout.TotalMilliseconds));
                }

                // Set the timeout to the default 5000 milliseconds.
                timeout = TimeSpan.FromMilliseconds(double.Parse("5000"));

                if (this.logger != null)
                {
                    this.logger.AddInfo(string.Format(
                                            "The timeout total milliseconds from the param \"timeout\" is set to the default value: {0} milliseconds.",
                                            timeout.TotalMilliseconds));
                }
            }

            DateTime startTime = DateTime.Now;

            while (this.segmentQueue.Count == 0)
            {
                // Waiting for the reqest.
                Thread.Sleep(100);
                if ((DateTime.Now - startTime).TotalMilliseconds > timeout.TotalMilliseconds)
                {
                    throw new NoSEGMENTINFOMESSAGEReceivedException(string.Format(
                                                                        "Waiting for {0} milliseconds, no expected SEGMENT_INFO_MESSAGE is received.",
                                                                        timeout.TotalMilliseconds));
                }
            }

            while (!this.segmentQueue.Peek().Request.RemoteEndPoint.Address.Equals(IPAddress.Parse(ipaddress)))
            {
                this.segmentQueue.Dequeue();
                if (this.segmentQueue.Count == 0)
                {
                    throw new InvalidOperationException();
                }

                this.httpRequest = this.segmentQueue.Peek().Request;
            }

            try
            {
                this.DecomposeHttpRequest(this.httpRequest);
            }
            catch (ObjectDisposedException e)
            {
                if (this.logger != null)
                {
                    this.logger.AddWarning(
                        string.Format("Object disposed exception is catched, detailed information: {0}.", e.Message));
                }
                else
                {
                    throw;
                }
            }

            return(DecodeMessage.DecodeSegmentInfoMessage(this.httpRequestPayload));
        }