In Name constructor, allow the argument to be another Name.
In Name.add, return this to allow chaining, and allow the argument to be another Name.
Added Name.addSegment.
diff --git a/js/tools/build/ndn-js-uncomp.js b/js/tools/build/ndn-js-uncomp.js
index b947a5c..274879c 100644
--- a/js/tools/build/ndn-js-uncomp.js
+++ b/js/tools/build/ndn-js-uncomp.js
@@ -633,6 +633,26 @@
return result;
};
+/**
+* @brief Add component that represents a segment number
+*
+* @param number Segment number (integer is expected)
+*
+* This component has a special format handling:
+* - if number is zero, then %00 is added
+* - if number is between 1 and 255, %00%01 .. %00%FF is added
+* - ...
+*/
+Name.prototype.addSegment = function(number) {
+ var segmentNumberBigEndian = DataUtils.nonNegativeIntToBigEndian(number);
+ // Put a 0 byte in front.
+ var segmentNumberComponent = new Uint8Array(segmentNumberBigEndian.length + 1);
+ segmentNumberComponent.set(segmentNumberBigEndian, 1);
+
+ this.components.push(segmentNumberComponent);
+ return this;
+};
+
/*
* Return a new Name with the first nComponents components of this Name.
*/