34 template<
class T,
class TR,
class AX>
35 void encode(_Inout_ std::basic_string<T, TR, AX> &out, _In_bytecount_(size)
const void *data, _In_
size_t size)
37 _Assume_(data || !size);
40 out.reserve(out.size() +
enc_size(size));
43 for (
size_t i = 0; i < size; i++) {
45 x =
reinterpret_cast<const uint8_t*
>(data)[i],
46 x_h = ((x & 0xf0) >> 4),
49 out += x_h < 10 ?
'0' + x_h :
'A' - 10 + x_h;
50 out += x_l < 10 ?
'0' + x_l :
'A' - 10 + x_l;
61 size_t enc_size(_In_
size_t size)
const noexcept
89 template<
class T_to,
class AX,
class T_from>
90 void decode(_Inout_ std::vector<T_to, AX> &out, _Out_
bool &is_last, _In_z_count_(size)
const T_from *data, _In_
size_t size)
95 for (
size_t k = 0; k < size; k++)
96 if (!data[k]) { size = k;
break; }
99 out.reserve(out.size() +
dec_size(size));
101 for (
size_t i = 0;; i++) {
114 if (
'0' <= x && x <=
'9') {
115 buf = ((
buf & 0xf) << 4) | (uint8_t)(x -
'0');
117 }
else if (
'A' <= x && x <=
'F') {
118 buf = ((
buf & 0xf) << 4) | (uint8_t)(x - (
'A' - 10));
120 }
else if (
'a' <= x && x <=
'f') {
121 buf = ((
buf & 0xf) << 4) | (uint8_t)(x - (
'a' - 10));
Hexadecimal decoding session.
Definition hex.hpp:71
void clear() noexcept
Resets decoding session.
Definition hex.hpp:130
uint8_t buf
Internal buffer.
Definition hex.hpp:148
hex_dec() noexcept
Constructs blank decoding session.
Definition hex.hpp:76
void decode(std::vector< T_to, AX > &out, bool &is_last, const T_from *data, size_t size)
Decodes one block of information, and appends it to the output.
Definition hex.hpp:90
size_t num
Number of nibbles used in buf
Definition hex.hpp:149
size_t dec_size(size_t size) const noexcept
Returns maximum decoded size.
Definition hex.hpp:142
Hexadecimal encoding session.
Definition hex.hpp:19
size_t enc_size(size_t size) const noexcept
Returns maximum encoded size.
Definition hex.hpp:61
void encode(std::basic_string< T, TR, AX > &out, const void *data, size_t size)
Encodes one block of information, and appends it to the output.
Definition hex.hpp:35
hex_enc() noexcept
Constructs blank encoding session.
Definition hex.hpp:24