blob: b72aee5f011a904ab3b872aef16fd68d9187cacd [file] [log] [blame]
<?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));
interest.exclude = new Exclude([Name.fromEscapedString("abc"), Exclude.ANY]);
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: " + interest.name.getName() + "<br/>";
if (interest.minSuffixComponents != null )
output += "MinSuffixComponents : " + interest.minSuffixComponents + "<br/>";
if (interest.maxSuffixComponents != null )
output += "MaxSuffixComponents : " + interest.maxSuffixComponents + "<br/>";
if (interest.publisherPublicKeyDigest != null )
output += "PublisherPublicKeyDigest: " +
DataUtils.toHex(interest.publisherPublicKeyDigest.publisherPublicKeyDigest) + "<br/>";
if (interest.childSelector != null )
output += "ChildSelector: " + interest.childSelector + "<br/>";
if (interest.answerOriginKind != null )
output += "AnswerOriginKind: " + interest.answerOriginKind + "<br/>";
if (interest.scope != null )
output += "Scope: " + interest.scope + "<br/>";
if (interest.interestLifetime != null )
output += "InterestLifetime (milliseconds): " + interest.interestLifetime + "<br/>";
if (interest.nonce != null )
output += "Nonce: " + DataUtils.toHex(interest.nonce) + "<br/>";
if (interest.exclude != null )
output += "Exclude: " + interest.exclude.to_uri() + "<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>