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

GetBytes() public static method

Get bytes from bytes.
public static GetBytes ( byte buffer, int &index, int count ) : byte[]
buffer byte the buffer stores the value.
index int the index of start to parse
count int count of bytes
return byte[]
        public static byte[] GetBytes(byte[] buffer, ref int index, int count)
        {
            byte[] byteReturn = null;

            if (count > 0)
            {
                byteReturn = new byte[count];

                Array.Copy(buffer, index, byteReturn, 0, byteReturn.Length);
                index += byteReturn.Length;
            }

            return byteReturn;
        }

Usage Example

Beispiel #1
0
        /// <summary>
        /// Get the request body byte array from the specified http request.
        /// </summary>
        /// <param name="httpListenerRequest">The specified http request.</param>
        /// <exception cref="ObjectDisposedException">
        /// Throw when an operation is performed on a disposed object.
        /// </exception>
        private void DecomposeHttpRequest(HttpListenerRequest httpListenerRequest)
        {
            if (httpListenerRequest == null)
            {
                throw new ArgumentNullException("httpListenerRequest");
            }

            this.httpRequestUri    = httpListenerRequest.Url;
            this.httpRequestMethod = httpListenerRequest.HttpMethod;

            try
            {
                Stream requestStream = httpListenerRequest.InputStream;

                byte[] payloadBuffer = new byte[this.bufferSize];
                int    readSize      = 0;
                while (true)
                {
                    int tempIndex = 0;
                    readSize = requestStream.Read(payloadBuffer, 0, payloadBuffer.Length);
                    if (readSize == 0)
                    {
                        break;
                    }
                    else
                    {
                        this.httpRequestPayload = DecodeMessage.GetBytes(payloadBuffer, ref tempIndex, readSize);
                    }
                }

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

            if (this.logger != null)
            {
                this.logger.AddDebug("Unmarshal PCHC request message is successfully.");
            }
        }