1
0
mirror of https://github.com/stefanocasazza/ULib.git synced 2025-09-28 19:05:55 +08:00
ULib/include/ulib/utility/hexdump.h
2017-11-30 16:54:08 +01:00

54 lines
1.4 KiB
C

// ============================================================================
//
// = LIBRARY
// ULib - c++ library
//
// = FILENAME
// hexdump.h
//
// = AUTHOR
// Stefano Casazza
//
// ============================================================================
#ifndef ULIB_HEXDUMP_H
#define ULIB_HEXDUMP_H 1
#include <ulib/base/coder/hexdump.h>
#include <ulib/string.h>
#define U_HEXDUMP(str) UHexDump::decode(U_CONSTANT_TO_PARAM(str))
struct U_EXPORT UHexDump {
static void encode(const char* s, uint32_t n, UString& buffer)
{
U_TRACE(0, "UHexDump::encode(%.*S,%u,%p)", n, s, n, &buffer)
U_ASSERT(buffer.uniq())
buffer.rep->_length = u_hexdump_encode((const unsigned char*)s, n, (unsigned char*)buffer.data());
}
static void encode(const UString& s, UString& buffer) { encode(U_STRING_TO_PARAM(s), buffer); }
static void decode(const char* s, uint32_t n, UString& buffer)
{
U_TRACE(0, "UHexDump::decode(%.*S,%u,%V)", n, s, n, buffer.rep)
U_ASSERT(buffer.uniq())
U_ASSERT(buffer.capacity() >= n)
buffer.rep->_length = u_hexdump_decode(s, n, (unsigned char*)buffer.data());
U_INTERNAL_DUMP("buffer(%u) = %#V", buffer.size(), buffer.rep)
}
static void decode(const UString& s, UString& buffer) { decode(U_STRING_TO_PARAM(s), buffer); }
static UString decode(const char* s, uint32_t n) { UString tmp(U_CAPACITY); decode(s, n, tmp); return tmp; }
};
#endif