24#ifndef MYSQL_HARNESS_HEXIFY_INCLUDED
25#define MYSQL_HARNESS_HEXIFY_INCLUDED
50 for (
auto cur =
reinterpret_cast<const uint8_t *
>(
buf.data()),
51 end = cur +
buf.size();
54 std::array<char, 16L * 3> hexline{
55 '.',
'.',
' ',
'.',
'.',
' ',
'.',
'.',
' ',
'.',
'.',
' ',
56 '.',
'.',
' ',
'.',
'.',
' ',
'.',
'.',
' ',
'.',
'.',
' ',
57 '.',
'.',
' ',
'.',
'.',
' ',
'.',
'.',
' ',
'.',
'.',
' ',
58 '.',
'.',
' ',
'.',
'.',
' ',
'.',
'.',
' ',
'.',
'.',
' '};
59 std::array<char, 16> printable;
61 for (
auto *hexline_pos = hexline.data(); cur != end && col < 16;
62 ++cur, ++col, hexline_pos += 3) {
65 const auto res = std::to_chars(hexline_pos, hexline_pos + 2, ch, 16);
66 if (res.ptr == hexline_pos + 1) {
68 hexline_pos[1] = std::exchange(hexline_pos[0],
'0');
71 printable[col] = std::isprint(ch) ?
static_cast<char>(ch) :
'.';
74 std::copy(hexline.begin(), hexline.end(), std::back_inserter(out));
78 for (
size_t ndx = 0; ndx < col; ++ndx) {
79 out.push_back(printable[ndx]);
Definition: buf0block_hint.cc:29
std::string hexify(const T &buf)
hexdump into a string.
Definition: hexify.h:47