Publish code submitted
CLASSES ADDED: Forwarding Entry and FaceInstance.
NOTE: the CCNx daemon doesn't accept the FaceInstance it receives.
Instead,
diff --git a/js/encoding/BinaryXMLDecoder.js b/js/encoding/BinaryXMLDecoder.js
index f70cca4..92e81f1 100644
--- a/js/encoding/BinaryXMLDecoder.js
+++ b/js/encoding/BinaryXMLDecoder.js
@@ -641,7 +641,6 @@
var TypeAndVal = function TypeAndVal(_type,_val) {
this.t = _type;
this.v = _val;
-
};
TypeAndVal.prototype.type = function(){
diff --git a/js/encoding/BinaryXMLEncoder.js b/js/encoding/BinaryXMLEncoder.js
index f05a869..a4217ff 100644
--- a/js/encoding/BinaryXMLEncoder.js
+++ b/js/encoding/BinaryXMLEncoder.js
@@ -21,7 +21,7 @@
var XML_CLOSE = 0x0;
var XML_SUBTYPE_PROCESSING_INSTRUCTIONS = 16;
-
+
var XML_TT_BITS = 3;
var XML_TT_MASK = ((1 << XML_TT_BITS) - 1);
@@ -57,7 +57,9 @@
BinaryXMLEncoder.prototype.writeBlob = function(/*byte []*/ binaryContent
//, /*int*/ offset, /*int*/ length
) {
- console.log(binaryContent);
+
+ if(LOG >3) console.log(binaryContent);
+
this.encodeBlob(this.ostream, binaryContent, this.offset, binaryContent.length);
};
@@ -144,13 +146,30 @@
//long
tag,
//byte[]
- binaryContent,
+ Content,
//TreeMap<String, String>
attributes) {
this.writeStartElement(tag, attributes);
// Will omit if 0-length
- this.writeBlob(binaryContent);
+ if(typeof Content === 'number') {
+ if(LOG>4) console.log('GOING TO WRITE THE NUMBER ' +Content );
+ this.writeBlob(Content.toString());
+ //whatever
+
+ }
+
+ else{
+ //else if(typeof Content === 'string'){
+ console.log('went here');
+ //this.writeBlob(Content);
+ //}
+
+ //else if(typeof Content === 'object'){
+ this.writeBlob(Content);
+ //}
+ }
+
this.writeEndElement();
}
@@ -314,11 +333,19 @@
//CCNTime
offset) {
-
- for (var i = 0; i < input.length; i++) {
- this.ostream[this.offset+i] = (input.charCodeAt(i));
+ if(typeof input === 'string'){
+ //console.log('went here');
+ if(LOG>4) console.log('GOING TO WRITE A STRING');
+
+ for (var i = 0; i < input.length; i++) {
+ this.ostream[this.offset+i] = (input.charCodeAt(i));
+ }
}
-
+
+ else if(typeof input === 'object'){
+ this.writeBlobArray(input);
+ }
+
};
BinaryXMLEncoder.prototype.writeBlobArray = function(
@@ -327,11 +354,16 @@
//CCNTime
offset) {
+ if(LOG>4) console.log('GOING TO WRITE A BLOB');
+
for (var i = 0; i < Blob.length; i++) {
this.ostream[this.offset+i] = Blob[i];
}
};
+
+
+
BinaryXMLEncoder.prototype.getReducedOstream = function() {
return this.ostream.slice(0,this.offset);
diff --git a/js/encoding/DataUtils.js b/js/encoding/DataUtils.js
index 92a4257..635cac7 100644
--- a/js/encoding/DataUtils.js
+++ b/js/encoding/DataUtils.js
@@ -97,10 +97,6 @@
return unescape(output);
};
-
-
-
-
//byte []
DataUtils.prototype.unsignedLongToByteArray= function( value) {
@@ -133,5 +129,29 @@
}
+var utf8 = {}
+
+utf8.toByteArray = function(str) {
+ var byteArray = [];
+ for (var i = 0; i < str.length; i++)
+ if (str.charCodeAt(i) <= 0x7F)
+ byteArray.push(str.charCodeAt(i));
+ else {
+ var h = encodeURIComponent(str.charAt(i)).substr(1).split('%');
+ for (var j = 0; j < h.length; j++)
+ byteArray.push(parseInt(h[j], 16));
+ }
+ return byteArray;
+};
+
+utf8.parse = function(byteArray) {
+ var str = '';
+ for (var i = 0; i < byteArray.length; i++)
+ str += byteArray[i] <= 0x7F?
+ byteArray[i] === 0x25 ? "%25" : // %
+ String.fromCharCode(byteArray[i]) :
+ "%" + byteArray[i].toString(16).toUpperCase();
+ return decodeURIComponent(str);
+};