/// <summary> /// Test encoding/decoding /// </summary> /// /// <exception cref="EncodingException"></exception> public void testEncodeDecode() { ControlParameters controlParameters = new ControlParameters(); controlParameters.setName(new Name("/test/control/parameters")); controlParameters.setFaceId(1); // encode Blob encoded = controlParameters.wireEncode(); // decode ControlParameters decodedControlParameters = new ControlParameters(); decodedControlParameters.wireDecode(encoded); // compare Assert.AssertEquals(controlParameters.getName().toUri(), decodedControlParameters.getName().toUri()); Assert.AssertEquals(controlParameters.getFaceId(), decodedControlParameters.getFaceId()); Assert.AssertEquals("decoded forwarding flags childInherit is different", controlParameters.getForwardingFlags().getChildInherit(), decodedControlParameters.getForwardingFlags().getChildInherit()); Assert.AssertEquals("decoded forwarding flags capture is different", controlParameters.getForwardingFlags().getCapture(), decodedControlParameters.getForwardingFlags().getCapture()); }
private static void encodeControlParameters( ControlParameters controlParameters, TlvEncoder encoder) { int saveLength = encoder.getLength(); // Encode backwards. encoder.writeOptionalNonNegativeIntegerTlvFromDouble( net.named_data.jndn.encoding.tlv.Tlv.ControlParameters_ExpirationPeriod, controlParameters.getExpirationPeriod()); // Encode strategy if (controlParameters.getStrategy().size() != 0) { int strategySaveLength = encoder.getLength(); encodeName(controlParameters.getStrategy(), new int[1], new int[1], encoder); encoder.writeTypeAndLength(net.named_data.jndn.encoding.tlv.Tlv.ControlParameters_Strategy, encoder.getLength() - strategySaveLength); } // Encode ForwardingFlags int flags = controlParameters.getForwardingFlags() .getNfdForwardingFlags(); if (flags != new ForwardingFlags().getNfdForwardingFlags()) // The flags are not the default value. encoder.writeNonNegativeIntegerTlv(net.named_data.jndn.encoding.tlv.Tlv.ControlParameters_Flags, flags); encoder.writeOptionalNonNegativeIntegerTlv(net.named_data.jndn.encoding.tlv.Tlv.ControlParameters_Cost, controlParameters.getCost()); encoder.writeOptionalNonNegativeIntegerTlv( net.named_data.jndn.encoding.tlv.Tlv.ControlParameters_Origin, controlParameters.getOrigin()); encoder.writeOptionalNonNegativeIntegerTlv( net.named_data.jndn.encoding.tlv.Tlv.ControlParameters_LocalControlFeature, controlParameters.getLocalControlFeature()); // Encode URI if (controlParameters.getUri().Length != 0) { encoder.writeBlobTlv(net.named_data.jndn.encoding.tlv.Tlv.ControlParameters_Uri, new Blob( controlParameters.getUri()).buf()); } encoder.writeOptionalNonNegativeIntegerTlv( net.named_data.jndn.encoding.tlv.Tlv.ControlParameters_FaceId, controlParameters.getFaceId()); // Encode name if (controlParameters.getName() != null) { encodeName(controlParameters.getName(), new int[1], new int[1], encoder); } encoder.writeTypeAndLength(net.named_data.jndn.encoding.tlv.Tlv.ControlParameters_ControlParameters, encoder.getLength() - saveLength); }