Ejemplo n.º 1
0
        public void Encode()
        {
            ControlResponse response = new ControlResponse();
            response.setStatusCode(404);
            response.setStatusText("Nothing not found");
            response.setBodyAsControlParameters(new ControlParameters());
            response.getBodyAsControlParameters().setFaceId(10);
            Blob wire = response.wireEncode();

            Assert.AssertEquals(wire.buf(), TestControlResponse1);
        }
Ejemplo n.º 2
0
        /// <summary>
        /// Decode input as a control parameters in NDN-TLV and set the fields of the
        /// controlResponse object.
        /// </summary>
        ///
        /// <param name="controlResponse"></param>
        /// <param name="input"></param>
        /// <param name="copy">unchanged while the Blob values are used.</param>
        /// <exception cref="EncodingException">For invalid encoding</exception>
        public override void decodeControlResponse(ControlResponse controlResponse,
				ByteBuffer input, bool copy)
        {
            TlvDecoder decoder = new TlvDecoder(input);
            int endOffset = decoder
                    .readNestedTlvsStart(net.named_data.jndn.encoding.tlv.Tlv.NfdCommand_ControlResponse);

            controlResponse.setStatusCode((int) decoder
                    .readNonNegativeIntegerTlv(net.named_data.jndn.encoding.tlv.Tlv.NfdCommand_StatusCode));
            // Set copy false since we just immediately get a string.
            Blob statusText = new Blob(
                    decoder.readBlobTlv(net.named_data.jndn.encoding.tlv.Tlv.NfdCommand_StatusText), false);
            controlResponse.setStatusText(statusText.toString());

            // Decode the body.
            if (decoder
                    .peekType(net.named_data.jndn.encoding.tlv.Tlv.ControlParameters_ControlParameters, endOffset)) {
                controlResponse.setBodyAsControlParameters(new ControlParameters());
                // Decode into the existing ControlParameters to avoid copying.
                decodeControlParameters(
                        controlResponse.getBodyAsControlParameters(), decoder, copy);
            } else
                controlResponse.setBodyAsControlParameters(null);

            decoder.finishNestedTlvs(endOffset);
        }