diff options
author | Andrew Morrow <acm@mongodb.com> | 2015-01-03 15:08:46 -0500 |
---|---|---|
committer | Andrew Morrow <acm@mongodb.com> | 2015-01-05 18:26:59 -0500 |
commit | d61eb5e43f1efe634be1a383ea451f8579dfb9fa (patch) | |
tree | 1c175fabf3ae10455d981808c9fd6fa37e189357 /src/mongo/util/hex.cpp | |
parent | ce14697bff987f49262f5da9f14e33f913ae9339 (diff) | |
download | mongo-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.cpp | 19 |
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; + } + } |