summaryrefslogtreecommitdiff
path: root/src/mongo/util/hex.cpp
diff options
context:
space:
mode:
authorAndrew Morrow <acm@mongodb.com>2015-01-03 15:08:46 -0500
committerAndrew Morrow <acm@mongodb.com>2015-01-05 18:26:59 -0500
commitd61eb5e43f1efe634be1a383ea451f8579dfb9fa (patch)
tree1c175fabf3ae10455d981808c9fd6fa37e189357 /src/mongo/util/hex.cpp
parentce14697bff987f49262f5da9f14e33f913ae9339 (diff)
downloadmongo-d61eb5e43f1efe634be1a383ea451f8579dfb9fa.tar.gz
SERVER-13256 Move hexdump out of goodies.h and into hex.h
Diffstat (limited to 'src/mongo/util/hex.cpp')
-rw-r--r--src/mongo/util/hex.cpp19
1 files changed, 18 insertions, 1 deletions
diff --git a/src/mongo/util/hex.cpp b/src/mongo/util/hex.cpp
index d02ac811711..3d6c1b45f86 100644
--- a/src/mongo/util/hex.cpp
+++ b/src/mongo/util/hex.cpp
@@ -27,9 +27,12 @@
* then also delete it in the license file.
*/
-#include <string>
#include "mongo/util/hex.h"
+#include <iomanip>
+#include <sstream>
+#include <string>
+
namespace mongo {
template<typename T>
@@ -65,4 +68,18 @@ namespace mongo {
template<> std::string integerToHex<unsigned long>(unsigned long val) { return integerToHexDef(val); }
template<> std::string integerToHex<long long>(long long val) { return integerToHexDef(val); }
template<> std::string integerToHex<unsigned long long>(unsigned long long val) { return integerToHexDef(val); }
+
+
+ string hexdump(const char *data, unsigned len) {
+ verify( len < 1000000 );
+ const unsigned char *p = (const unsigned char *) data;
+ std::stringstream ss;
+ ss << std::hex << std::setw(2) << std::setfill('0');
+ for( unsigned i = 0; i < len; i++ ) {
+ ss << static_cast<unsigned>(p[i]) << ' ';
+ }
+ std::string s = ss.str();
+ return s;
+ }
+
}