/// <summary> /// Test encoding/decoding with no name defined /// </summary> /// /// <exception cref="EncodingException"></exception> public void testEncodeDecodeWithNoName() { ControlParameters controlParameters = new ControlParameters(); controlParameters.setStrategy(new Name( "/localhost/nfd/strategy/broadcast")); controlParameters.setUri("null://"); // encode Blob encoded = controlParameters.wireEncode(); // decode ControlParameters decodedControlParameters = new ControlParameters(); decodedControlParameters.wireDecode(encoded); // compare Assert.AssertEquals(controlParameters.getStrategy().toUri(), decodedControlParameters.getStrategy().toUri()); Assert.AssertEquals(controlParameters.getUri(), decodedControlParameters.getUri()); }
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); }
private static void decodeControlParameters( ControlParameters controlParameters, TlvDecoder decoder, bool copy) { controlParameters.clear(); int endOffset = decoder .readNestedTlvsStart(net.named_data.jndn.encoding.tlv.Tlv.ControlParameters_ControlParameters); // decode name if (decoder.peekType(net.named_data.jndn.encoding.tlv.Tlv.Name, endOffset)) { Name name = new Name(); decodeName(name, new int[1], new int[1], decoder, copy); controlParameters.setName(name); } // decode face ID controlParameters.setFaceId((int) decoder .readOptionalNonNegativeIntegerTlv( net.named_data.jndn.encoding.tlv.Tlv.ControlParameters_FaceId, endOffset)); // decode URI if (decoder.peekType(net.named_data.jndn.encoding.tlv.Tlv.ControlParameters_Uri, endOffset)) { // Set copy false since we just immediately get the string. Blob uri = new Blob(decoder.readOptionalBlobTlv( net.named_data.jndn.encoding.tlv.Tlv.ControlParameters_Uri, endOffset), false); controlParameters.setUri("" + uri); } // decode integers controlParameters.setLocalControlFeature((int) decoder .readOptionalNonNegativeIntegerTlv( net.named_data.jndn.encoding.tlv.Tlv.ControlParameters_LocalControlFeature, endOffset)); controlParameters.setOrigin((int) decoder .readOptionalNonNegativeIntegerTlv( net.named_data.jndn.encoding.tlv.Tlv.ControlParameters_Origin, endOffset)); controlParameters.setCost((int) decoder .readOptionalNonNegativeIntegerTlv(net.named_data.jndn.encoding.tlv.Tlv.ControlParameters_Cost, endOffset)); // set forwarding flags if (decoder.peekType(net.named_data.jndn.encoding.tlv.Tlv.ControlParameters_Flags, endOffset)) { ForwardingFlags flags = new ForwardingFlags(); flags.setNfdForwardingFlags((int) decoder .readNonNegativeIntegerTlv(net.named_data.jndn.encoding.tlv.Tlv.ControlParameters_Flags)); controlParameters.setForwardingFlags(flags); } // decode strategy if (decoder.peekType(net.named_data.jndn.encoding.tlv.Tlv.ControlParameters_Strategy, endOffset)) { int strategyEndOffset = decoder .readNestedTlvsStart(net.named_data.jndn.encoding.tlv.Tlv.ControlParameters_Strategy); decodeName(controlParameters.getStrategy(), new int[1], new int[1], decoder, copy); decoder.finishNestedTlvs(strategyEndOffset); } // decode expiration period controlParameters.setExpirationPeriod(decoder .readOptionalNonNegativeIntegerTlv( net.named_data.jndn.encoding.tlv.Tlv.ControlParameters_ExpirationPeriod, endOffset)); decoder.finishNestedTlvs(endOffset); }