Name: Added appendVersion. Added Name::Component::fromNumberWithMarker.
diff --git a/ndn-cpp/name.cpp b/ndn-cpp/name.cpp
index 4e619cc..c9b5e7f 100644
--- a/ndn-cpp/name.cpp
+++ b/ndn-cpp/name.cpp
@@ -124,8 +124,8 @@
return result;
}
-Blob
-Name::Component::makeFromEscapedString(const char *escapedString, size_t beginOffset, size_t endOffset)
+Name::Component
+Name::Component::fromEscapedString(const char *escapedString, size_t beginOffset, size_t endOffset)
{
string trimmedString(escapedString + beginOffset, escapedString + endOffset);
trim(trimmedString);
@@ -135,27 +135,43 @@
// Special case for component of only periods.
if (component.size() <= 2)
// Zero, one or two periods is illegal. Ignore this component.
- return Blob();
+ return Component();
else
// Remove 3 periods.
- return Blob((const uint8_t *)&component[3], component.size() - 3);
+ return Component((const uint8_t *)&component[3], component.size() - 3);
}
else
- return Blob((const uint8_t *)&component[0], component.size());
+ return Component((const uint8_t *)&component[0], component.size());
}
-Blob
-Name::Component::makeSegment(unsigned long segment)
+Name::Component
+Name::Component::fromNumber(uint64_t number)
{
shared_ptr<vector<uint8_t> > value(new vector<uint8_t>());
- // Add the leading zero.
- value->push_back(0);
+ // First encode in little endian.
+ while (number != 0) {
+ value->push_back(number & 0xff);
+ number >>= 8;
+ }
+
+ // Make it big endian.
+ reverse(value->begin(), value->end());
+ return Blob(value);
+}
+
+Name::Component
+Name::Component::fromNumberWithMarker(uint64_t number, uint8_t marker)
+{
+ shared_ptr<vector<uint8_t> > value(new vector<uint8_t>());
+
+ // Add the leading marker.
+ value->push_back(marker);
// First encode in little endian.
- while (segment != 0) {
- value->push_back(segment & 0xff);
- segment >>= 8;
+ while (number != 0) {
+ value->push_back(number & 0xff);
+ number >>= 8;
}
// Make it big endian.
@@ -225,9 +241,9 @@
if (iComponentEnd == string::npos)
iComponentEnd = uri.size();
- Blob component = Component::makeFromEscapedString(&uri[0], iComponentStart, iComponentEnd);
+ Component component = Component::fromEscapedString(&uri[0], iComponentStart, iComponentEnd);
// Ignore illegal components. This also gets rid of a trailing '/'.
- if (component)
+ if (component.getValue())
components_.push_back(Component(component));
iComponentStart = iComponentEnd + 1;