38 template<
class _Elem,
class _Traits,
class _Ax>
39 void encode(_Inout_ std::basic_string<_Elem, _Traits, _Ax> &out, _In_bytecount_(size)
const void *data, _In_
size_t size)
41 assert(data || !size);
44 out.reserve(out.size() +
enc_size(size));
47 for (
size_t i = 0; i < size; i++) {
49 x =
reinterpret_cast<const uint8_t*
>(data)[i],
50 x_h = ((x & 0xf0) >> 4),
53 out += x_h < 10 ?
'0' + x_h :
'A' - 10 + x_h;
54 out += x_l < 10 ?
'0' + x_l :
'A' - 10 + x_l;
66 size_t enc_size(_In_
size_t size)
const noexcept
97 template<
class _Ty,
class _Ax,
class _Tchr>
98 void decode(_Inout_ std::vector<_Ty, _Ax> &out, _Out_
bool &is_last, _In_z_count_(size)
const _Tchr *data, _In_
size_t size)
103 for (
size_t k = 0; k < size; k++)
104 if (!data[k]) { size = k;
break; }
107 out.reserve(out.size() +
dec_size(size));
109 for (
size_t i = 0;; i++) {
122 if (
'0' <= x && x <=
'9') {
123 buf = ((
buf & 0xf) << 4) | (uint8_t)(x -
'0');
125 }
else if (
'A' <= x && x <=
'F') {
126 buf = ((
buf & 0xf) << 4) | (uint8_t)(x - (
'A' - 10));
128 }
else if (
'a' <= x && x <=
'f') {
129 buf = ((
buf & 0xf) << 4) | (uint8_t)(x - (
'a' - 10));
Hexadecimal decoding session.
Definition: hex.hpp:77
void clear() noexcept
Resets decoding session.
Definition: hex.hpp:139
uint8_t buf
Internal buffer.
Definition: hex.hpp:159
hex_dec() noexcept
Constructs blank decoding session.
Definition: hex.hpp:82
size_t num
Number of nibbles used in buf
Definition: hex.hpp:160
void decode(std::vector< _Ty, _Ax > &out, bool &is_last, const _Tchr *data, size_t size)
Decodes one block of information, and appends it to the output.
Definition: hex.hpp:98
size_t dec_size(size_t size) const noexcept
Returns maximum decoded size.
Definition: hex.hpp:152
Hexadecimal encoding session.
Definition: hex.hpp:21
size_t enc_size(size_t size) const noexcept
Returns maximum encoded size.
Definition: hex.hpp:66
void encode(std::basic_string< _Elem, _Traits, _Ax > &out, const void *data, size_t size)
Encodes one block of information, and appends it to the output.
Definition: hex.hpp:39
hex_enc() noexcept
Constructs blank encoding session.
Definition: hex.hpp:26