35 template<
class _Elem,
class _Traits,
class _Ax>
36 void encode(_Inout_ std::basic_string<_Elem, _Traits, _Ax> &out, _In_bytecount_(size)
const void *data, _In_
size_t size)
38 assert(data || !size);
41 out.reserve(out.size() +
enc_size(size));
44 for (
size_t i = 0; i < size; i++) {
46 x =
reinterpret_cast<const unsigned char*
>(data)[i],
47 x_h = ((x & 0xf0) >> 4),
50 out += x_h < 10 ?
'0' + x_h :
'A' - 10 + x_h;
51 out += x_l < 10 ?
'0' + x_l :
'A' - 10 + x_l;
94 template<
class _Ty,
class _Ax,
class _Tchr>
95 void decode(_Inout_ std::vector<_Ty, _Ax> &out, _Out_
bool &is_last, _In_z_count_(size)
const _Tchr *data, _In_
size_t size)
100 for (
size_t k = 0; k < size; k++)
101 if (!data[k]) { size = k;
break; }
104 out.reserve(out.size() +
dec_size(size));
106 for (
size_t i = 0;; i++) {
119 if (
'0' <= x && x <=
'9') {
120 buf = ((
buf & 0xf) << 4) | (
unsigned char)(x -
'0');
122 }
else if (
'A' <= x && x <=
'F') {
123 buf = ((
buf & 0xf) << 4) | (
unsigned char)(x - (
'A' - 10));
125 }
else if (
'a' <= x && x <=
'f') {
126 buf = ((
buf & 0xf) << 4) | (
unsigned char)(x - (
'a' - 10));
Hexadecimal decoding session.
Definition: hex.h:74
unsigned char buf
Internal buffer.
Definition: hex.h:156
void clear() noexcept
Resets decoding session.
Definition: hex.h:136
hex_dec() noexcept
Constructs blank decoding session.
Definition: hex.h:79
size_t num
Number of nibbles used in buf
Definition: hex.h:157
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.h:95
size_t dec_size(size_t size) const noexcept
Returns maximum decoded size.
Definition: hex.h:149
Hexadecimal encoding session.
Definition: hex.h:18
size_t enc_size(size_t size) const noexcept
Returns maximum encoded size.
Definition: hex.h:63
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.h:36
hex_enc() noexcept
Constructs blank encoding session.
Definition: hex.h:23