util: add printHex() overload that takes a uint64_t
And AsHex helper class.
Change-Id: If6fb6edea258ab281b5ea9cc30deffd2d8994dc5
Refs: #3006
diff --git a/src/util/string-helper.cpp b/src/util/string-helper.cpp
index 3d4ea3f..7665afc 100644
--- a/src/util/string-helper.cpp
+++ b/src/util/string-helper.cpp
@@ -31,6 +31,24 @@
namespace ndn {
+std::ostream&
+operator<<(std::ostream& os, const AsHex& hex)
+{
+ printHex(os, hex.m_value, os.flags() & std::ostream::uppercase);
+ return os;
+}
+
+void
+printHex(std::ostream& os, uint64_t num, bool wantUpperCase)
+{
+ auto osFlags = os.flags();
+ // std::showbase doesn't work with number 0
+ os << "0x" << std::noshowbase << std::noshowpos
+ << (wantUpperCase ? std::uppercase : std::nouppercase)
+ << std::hex << num;
+ os.flags(osFlags);
+}
+
void
printHex(std::ostream& os, const uint8_t* buffer, size_t length, bool wantUpperCase)
{