28 static const uint8_t
H2CL[] = {
29 '0',
'1',
'2',
'3',
'4',
'5',
'6',
'7',
30 '8',
'9',
'a',
'b',
'c',
'd',
'e',
'f' 32 static_assert(std::extent<decltype(H2CL)>::value == 16,
"");
34 static const uint8_t
H2CU[] = {
35 '0',
'1',
'2',
'3',
'4',
'5',
'6',
'7',
36 '8',
'9',
'A',
'B',
'C',
'D',
'E',
'F' 38 static_assert(std::extent<decltype(H2CU)>::value == 16,
"");
42 : m_useUpperCase(useUpperCase)
47 HexEncode::convert(
const uint8_t* data,
size_t dataLen)
53 unique_ptr<Transform::OBuffer>
54 HexEncode::toHex(
const uint8_t* data,
size_t dataLen)
56 auto encoded = make_unique<OBuffer>(dataLen * 2);
57 uint8_t* buf = encoded->data();
58 const uint8_t* encodePad = m_useUpperCase ?
H2CU :
H2CL;
60 for (
size_t i = 0; i < dataLen; i++) {
61 buf[0] = encodePad[(data[i] >> 4) & 0x0F];
62 buf[1] = encodePad[data[i] & 0x0F];
72 return make_unique<HexEncode>(useUpperCase);