37 template<
class _Elem,
class _Traits,
class _Ax>
38 void encode(_Inout_ std::basic_string<_Elem, _Traits, _Ax> &out, _In_bytecount_(size)
const void *data, _In_
size_t size)
40 _Assume_(data || !size);
43 out.reserve(out.size() +
enc_size(size));
46 for (
size_t i = 0; i < size; i++) {
48 x =
reinterpret_cast<const uint8_t*
>(data)[i],
49 x_h = ((x & 0xf0) >> 4),
52 out += x_h < 10 ?
'0' + x_h :
'A' - 10 + x_h;
53 out += x_l < 10 ?
'0' + x_l :
'A' - 10 + x_l;
65 size_t enc_size(_In_
size_t size)
const noexcept
96 template<
class _Ty,
class _Ax,
class _Tchr>
97 void decode(_Inout_ std::vector<_Ty, _Ax> &out, _Out_
bool &is_last, _In_z_count_(size)
const _Tchr *data, _In_
size_t size)
102 for (
size_t k = 0; k < size; k++)
103 if (!data[k]) { size = k;
break; }
106 out.reserve(out.size() +
dec_size(size));
108 for (
size_t i = 0;; i++) {
121 if (
'0' <= x && x <=
'9') {
122 buf = ((
buf & 0xf) << 4) | (uint8_t)(x -
'0');
124 }
else if (
'A' <= x && x <=
'F') {
125 buf = ((
buf & 0xf) << 4) | (uint8_t)(x - (
'A' - 10));
127 }
else if (
'a' <= x && x <=
'f') {
128 buf = ((
buf & 0xf) << 4) | (uint8_t)(x - (
'a' - 10));
Hexadecimal decoding session.
Definition hex.hpp:76
void clear() noexcept
Resets decoding session.
Definition hex.hpp:138
uint8_t buf
Internal buffer.
Definition hex.hpp:158
hex_dec() noexcept
Constructs blank decoding session.
Definition hex.hpp:81
size_t num
Number of nibbles used in buf
Definition hex.hpp:159
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:97
size_t dec_size(size_t size) const noexcept
Returns maximum decoded size.
Definition hex.hpp:151
Hexadecimal encoding session.
Definition hex.hpp:20
size_t enc_size(size_t size) const noexcept
Returns maximum encoded size.
Definition hex.hpp:65
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:38
hex_enc() noexcept
Constructs blank encoding session.
Definition hex.hpp:25