26 static const uint8_t H2CL[] = {
27 '0',
'1',
'2',
'3',
'4',
'5',
'6',
'7',
28 '8',
'9',
'a',
'b',
'c',
'd',
'e',
'f'
30 static_assert(std::extent_v<decltype(H2CL)> == 16);
32 static const uint8_t H2CU[] = {
33 '0',
'1',
'2',
'3',
'4',
'5',
'6',
'7',
34 '8',
'9',
'A',
'B',
'C',
'D',
'E',
'F'
36 static_assert(std::extent_v<decltype(H2CU)> == 16);
39 HexEncode::convert(span<const uint8_t> data)
45 unique_ptr<Transform::OBuffer>
46 HexEncode::toHex(
const uint8_t* data,
size_t dataLen)
48 auto encoded = make_unique<OBuffer>(dataLen * 2);
49 uint8_t* buf = encoded->data();
50 const uint8_t* encodePad = m_useUpperCase ? H2CU : H2CL;
52 for (
size_t i = 0; i < dataLen; i++) {
53 buf[0] = encodePad[(data[i] >> 4) & 0x0F];
54 buf[1] = encodePad[data[i] & 0x0F];
64 return make_unique<HexEncode>(useUpperCase);