Пример #1
0
        private void Respond(Request request, bool isPiggyBacked = false)
        {
            var type = isPiggyBacked ? MessageType.Acknowledgement : request.Type;
            var code = CodeRegistry.Content;
            var payload = new byte[0];

            try {
                payload = _resource.Get(request.Uri);
            }
            catch (ResponseError error) {
                code = error.Code;
            }

            var response = new Response(type, code) {
                Payload = payload,
                RemoteAddress = request.RemoteAddress,
                Port = request.Port,
                Token = request.Token
            };

            if (isPiggyBacked) {
                response.Id = request.Id;
            }

            _messageLayer.Send(response);
        }
Пример #2
0
 public void Should_ignore_duplicated_messages()
 {
     var response = new Response(MessageType.NonConfirmable, CodeRegistry.Content) { Id = 1 };
     _messageLayer.OnReceive(response);
     _messageLayer.OnReceive(response);
     _observer.Verify(h => h.OnReceive(response), Times.Once());
 }
 public void Should_serialize_payload()
 {
     var response = new Response(MessageType.Acknowledgement, CodeRegistry.Content) { Payload = ByteConverter.GetBytes("22.5 C") };
     var bytes = _serializer.Serialize(response);
     var bits = Util.GetBits(bytes, 4, 6);
     Assert.AreEqual("001100100011001000101110001101010010000001000011", bits);
 }
Пример #4
0
 public static Response Simple_atomic_blockwise_put_with_negotiation_response(int num)
 {
     var m = num < 6 ? 1 : 0;
     var response = new Response(MessageType.Acknowledgement, CodeRegistry.Changed) { Id = 1234, Token = ByteConverter.GetBytes(0x17) };
     response.AddOption(new BlockOption(OptionNumber.Block1, num, m, BlockOption.EncodeSzx(32)));
     return response;
 }
Пример #5
0
 public void Response_should_be_piggy_backed()
 {
     var response = new Response(MessageType.Acknowledgement, CodeRegistry.Content) { Payload = new byte[10] };
     Assert.IsTrue(response.IsPiggyBacked);
 }
Пример #6
0
 public void Non_confirmable_message_message_should_carry_response()
 {
     var response = new Response(MessageType.NonConfirmable, CodeRegistry.Created);
     Assert.IsNotNull(response);
 }
Пример #7
0
 public void Acknowledgement_message_should_carry_response()
 {
     var response = new Response(MessageType.Acknowledgement, CodeRegistry.Created);
     Assert.IsNotNull(response);
 }
Пример #8
0
 public static Response Simple_blockwise_get_block(int num)
 {
     var id = 1234 + num;
     var m = num < 2 ? 1 : 0;
     var block = new Response(MessageType.Acknowledgement, CodeRegistry.Content) { Id = id, Payload = new byte[128] };
     block.AddOption(new BlockOption(OptionNumber.Block2, num, m, BlockOption.EncodeSzx(128)));
     return block;
 }