encoding: Optimized Data packet encoding, preparation for memory-efficient signing operation
Change-Id: I6eb1f8acef917970790d1f228ade6212c45181fa
refs: #1172
diff --git a/src/util/string-helper.hpp b/src/util/string-helper.hpp
index de0c41f..14f499e 100644
--- a/src/util/string-helper.hpp
+++ b/src/util/string-helper.hpp
@@ -16,6 +16,29 @@
static const char *WHITESPACE_CHARS = " \n\r\t";
/**
+ * Return the hex representation of the bytes in array.
+ * @param array The array of bytes.
+ * @return Hex string.
+ */
+inline std::string
+toHex(const uint8_t* array, size_t arraySize)
+{
+ if (!&array)
+ return "";
+
+ std::ostringstream result;
+ result.flags(std::ios::hex | std::ios::uppercase);
+ for (size_t i = 0; i < arraySize; ++i) {
+ uint8_t x = array[i];
+ if (x < 16)
+ result << '0';
+ result << (unsigned int)x;
+ }
+
+ return result.str();
+}
+
+/**
* Modify str in place to erase whitespace on the left.
* @param str
*/
diff --git a/src/util/time.hpp b/src/util/time.hpp
index 5d729d9..e0b3727 100644
--- a/src/util/time.hpp
+++ b/src/util/time.hpp
@@ -12,6 +12,17 @@
namespace ndn {
+/**
+ * A time interval represented as the number of milliseconds.
+ */
+typedef int64_t Milliseconds;
+
+/**
+ * The calendar time represented as the number of milliseconds since 1/1/1970.
+ */
+typedef int64_t MillisecondsSince1970;
+
+
const boost::posix_time::ptime UNIX_EPOCH_TIME =
boost::posix_time::ptime (boost::gregorian::date (1970, boost::gregorian::Jan, 1));
@@ -30,6 +41,11 @@
return getNowMilliseconds();
}
+inline MillisecondsSince1970
+getNow()
+{
+ return getNowMilliseconds();
+}
/**
* Convert to the ISO string representation of the time.