当前位置: 首页>>代码示例>>C#>>正文


C# Response.GetOptions方法代码示例

本文整理汇总了C#中Response.GetOptions方法的典型用法代码示例。如果您正苦于以下问题:C# Response.GetOptions方法的具体用法?C# Response.GetOptions怎么用?C# Response.GetOptions使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在Response的用法示例。


在下文中一共展示了Response.GetOptions方法的4个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。

示例1: GetNextResponseBlock

        private Response GetNextResponseBlock(Response response, BlockwiseStatus status)
        {
            Int32 szx = status.CurrentSZX;
            Int32 num = status.CurrentNUM;
            Response block = new Response(response.StatusCode);
            // block.setType(response.getType()); // NO! First block has type from origin response, all other depend on current request
            block.Destination = response.Destination;
            block.Token = response.Token;
            block.SetOptions(response.GetOptions());
            block.TimedOut += (o, e) => response.IsTimedOut = true;

            Int32 payloadSize = response.PayloadSize;
            Int32 currentSize = 1 << (4 + szx);
            Int32 from = num * currentSize;
            if (payloadSize > 0 && payloadSize > from)
            {
                Int32 to = Math.Min((num + 1) * currentSize, response.PayloadSize);
                Int32 length = to - from;
                Byte[] blockPayload = new Byte[length];
                Array.Copy(response.Payload, from, blockPayload, 0, length);
                block.Payload = blockPayload;

                Boolean m = to < response.PayloadSize;
                block.AddOption(new BlockOption(OptionType.Block2, num, szx, m));
                block.Last = !m;

                status.Complete = !m;
            }
            else
            {
                block.AddOption(new BlockOption(OptionType.Block2, num, szx, false));
                block.Last = true;
                status.Complete = true;
            }

            return block;
        }
开发者ID:Kulak,项目名称:CoAP.NET,代码行数:37,代码来源:BlockwiseLayer.cs

示例2: TestResponseParsing

        public void TestResponseParsing()
#endif
        {
            Response response = new Response(StatusCode.Content);
            response.Type = MessageType.NON;
            response.ID = 9;
            response.Token = new Byte[] { 22, 255, 0, 78, 100, 22 };
            response.AddETag(new Byte[] { 1, 0, 0, 0, 0, 1 })
                                .AddLocationPath("/one/two/three/four/five/six/seven/eight/nine/ten")
                                .AddOption(Option.Create((OptionType)57453, "Arbitrary".GetHashCode()))
                                .AddOption(Option.Create((OptionType)19205, "Arbitrary1"))
                                .AddOption(Option.Create((OptionType)19205, "Arbitrary2"))
                                .AddOption(Option.Create((OptionType)19205, "Arbitrary3"));

            Byte[] bytes = Spec.NewMessageEncoder().Encode(response);

            IMessageDecoder decoder = Spec.NewMessageDecoder(bytes);
            Assert.IsTrue(decoder.IsResponse);

            Response result = decoder.DecodeResponse();
            Assert.AreEqual(response.ID, result.ID);
            Assert.IsTrue(response.Token.SequenceEqual(result.Token));
            Assert.IsTrue(response.GetOptions().SequenceEqual(result.GetOptions()));
        }
开发者ID:rlusian1,项目名称:CoAP.NET,代码行数:24,代码来源:MessageTest.cs

示例3: GetNextResponseBlock

        private Response GetNextResponseBlock(Response response, BlockwiseStatus status)
        {
            Response block;
            Int32 szx = status.CurrentSZX;
            Int32 num = status.CurrentNUM;

            if (response.HasOption(OptionType.Observe))
            {
                // a blockwise notification transmits the first block only
                block = response;
            }
            else
            {
                block = new Response(response.StatusCode);
                block.Destination = response.Destination;
                block.Token = response.Token;
                block.SetOptions(response.GetOptions());
                block.TimedOut += (o, e) => response.IsTimedOut = true;
            }

            Int32 payloadSize = response.PayloadSize;
            Int32 currentSize = 1 << (4 + szx);
            Int32 from = num * currentSize;
            if (payloadSize > 0 && payloadSize > from)
            {
                Int32 to = Math.Min((num + 1) * currentSize, response.PayloadSize);
                Int32 length = to - from;
                Byte[] blockPayload = new Byte[length];
                Boolean m = to < response.PayloadSize;
                block.SetBlock2(szx, m, num);

                // crop payload -- do after calculation of m in case block==response
                Array.Copy(response.Payload, from, blockPayload, 0, length);
                block.Payload = blockPayload;

                // do not complete notifications
                block.Last = !m && !response.HasOption(OptionType.Observe);

                status.Complete = !m;
            }
            else
            {
                block.AddOption(new BlockOption(OptionType.Block2, num, szx, false));
                block.Last = true;
                status.Complete = true;
            }

            return block;
        }
开发者ID:vjine,项目名称:CoAP.NET,代码行数:49,代码来源:BlockwiseLayer.cs

示例4: GetResponse

        /// <summary>
        /// Fills the new response with the response received from the internal CoAP
	    /// node. Simply copies the options and the payload from the forwarded
        /// response to the new one.
        /// </summary>
        /// <param name="incomingResponse">the forwarded request</param>
        /// <exception cref="ArgumentNullException">the <paramref name="incomingResponse"/> is null</exception>
        /// <returns></returns>
        public static Response GetResponse(Response incomingResponse)
        {
            if (incomingResponse == null)
                throw ThrowHelper.ArgumentNull("incomingResponse");

            Response outgoingResponse = new Response(incomingResponse.StatusCode);

            // copy payload
            Byte[] payload = incomingResponse.Payload;
            outgoingResponse.Payload = payload;

            // copy the timestamp
            outgoingResponse.Timestamp = incomingResponse.Timestamp;

            // copy every option
            outgoingResponse.SetOptions(incomingResponse.GetOptions());

            return outgoingResponse;
        }
开发者ID:rlusian1,项目名称:CoAP.NET,代码行数:27,代码来源:CoapTranslator.cs


注:本文中的Response.GetOptions方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。