Commit 277b44c6 authored by David COME's avatar David COME
Browse files

Added a nice toHexString utility function

parent 282dad3b
......@@ -45,7 +45,17 @@
#include <arpa/inet.h>
#include <sys/socket.h>
//-----------------------------------------------------------------------------
// toHexString
//-----------------------------------------------------------------------------
std::string castor::tape::utils::toHexString( const void * mem, unsigned int n ){
std::ostringstream out;
const unsigned char * p = reinterpret_cast< const unsigned char *>( mem );
for ( unsigned int i = 0; i < n; i++ ) {
out << std::uppercase << std::hex << std::setw(2) << std::setfill( out.widen('0') ) << int(p[i]) << " ";
}
return out.str();
}
//-----------------------------------------------------------------------------
// writeStrings
//-----------------------------------------------------------------------------
......
......@@ -102,7 +102,13 @@
namespace castor {
namespace tape {
namespace utils {
/**
* Will give an hexadecimal dump of the data between mem and mem+n
* @param mem THe pointer to memory do dump
* @param n The length of the memory
* @return The hex dump of the memory
*/
std::string toHexString( const void * mem, unsigned int n );
/**
* Writes the specified array of strings to the specified output stream as a
* list of strings separated by the specified separator.
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment