<?xml version = "1.0" encoding="utf-8" ?> | |
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" | |
"DTD/xhtml1-strict.dtd"> | |
<!-- | |
See COPYING for copyright and distribution information. | |
--> | |
<html xmlns = "http://www.w3.org/1999/xhtml"> | |
<head> | |
<title>NDN Encode/Decode Interest</title> | |
<script type="text/javascript" src="../Helper.js"></script> | |
<script type="text/javascript"> | |
function encode() { | |
var interest = new Interest( new Name(document.getElementById('interest').value ) ); | |
interest.minSuffixComponents = 2; | |
interest.maxSuffixComponents = 4; | |
interest.childSelector = 1; | |
interest.answerOriginKind = 4; | |
interest.scope = 2; | |
interest.interestLifetime = 30000; | |
interest.nonce = new Uint8Array([0x61, 0x62, 0x61, 0x62, 0x61, 0x62]); | |
var pkd = []; | |
for (i = 0; i < 32; ++i) | |
pkd.push(i); | |
interest.publisherPublicKeyDigest = new PublisherPublicKeyDigest(new Uint8Array(pkd)); | |
var output = encodeToHexInterest(interest); | |
document.getElementById('result').innerHTML = output; | |
} | |
function decode() { | |
var input = document.getElementById('result').innerHTML; | |
var interest = decodeHexInterest(input); | |
if (LOG>3)console.log('INTEREST DECODED'); | |
if (LOG>3)console.log(interest); | |
/////////////////////////////////////// | |
var output =""; | |
if (interest.name != null && interest.name.components != null) { | |
output += "Name: "; | |
output += interest.name.getName(); | |
output += "<br/>"; | |
} | |
if (interest.minSuffixComponents != null ) { | |
output += "MinSuffixComponents : "; | |
output += interest.minSuffixComponents; | |
output += "<br/>"; | |
} | |
if (interest.maxSuffixComponents != null ) { | |
output += "MaxSuffixComponents : "; | |
output += interest.maxSuffixComponents; | |
output += "<br/>"; | |
} | |
if (interest.publisherPublicKeyDigest != null ) { | |
output += "PublisherPublicKeyDigest: "; | |
output += DataUtils.toHex(interest.publisherPublicKeyDigest.publisherPublicKeyDigest); | |
output += "<br/>"; | |
} | |
if (interest.childSelector != null ) { | |
output += "ChildSelector: "; | |
output += interest.childSelector; | |
output += "<br/>"; | |
} | |
if (interest.answerOriginKind != null ) { | |
output += "AnswerOriginKind: "; | |
output += interest.answerOriginKind; | |
output += "<br/>"; | |
} | |
if (interest.scope != null ) { | |
output += "Scope: "; | |
output += interest.scope; | |
output += "<br/>"; | |
} | |
if (interest.interestLifetime != null ) { | |
output += "InterestLifetime (milliseconds): "; | |
output += interest.interestLifetime; | |
output += "<br/>"; | |
} | |
if (interest.nonce != null ) { | |
output += "Nonce: "; | |
output += DataUtils.toHex(interest.nonce); | |
output += "<br/>"; | |
} | |
document.getElementById('result').innerHTML = output; | |
} | |
</script> | |
</head> | |
<body > | |
<form> | |
Please Enter an Interest:<br /> | |
<input id="interest" type="text" name="INTEREST" value="/ndn/abc" /> | |
</form> | |
<button onclick="encode()">Encode</button> | |
<button onclick="decode()">Decode</button> | |
<p id="result"></p> | |
<!-- p id="result">01d2f2fafdc12e4d2e532e6c6f63616c686f737400fabdc12e4d2e53525600faa563636e6400fa9d4b4559000002d28e310000</p--> | |
</body> | |
</html> |