Encoders, decoders and helpers for hexadecimal representations.
Definition in file hex.hpp.
Go to the source code of this file.
#include <cstdint>
#include <string>
Namespaces | |
namespace | utils |
Utilities. | |
Functions | |
char | utils::encoding::ToHexChar (int num) |
Converts number to hex character; number must be within range [0,16) | |
constexpr size_t | utils::encoding::FromHexUpperBound (size_t size) noexcept |
Return upper limit on number of characters required to unhex input of given size. | |
void | utils::encoding::ToHex (std::string_view input, std::string &out) noexcept |
Converts input to hex and writes data to output out . | |
std::string | utils::encoding::ToHex (std::string_view data) noexcept |
Allocates std::string, converts input and writes into said string. | |
std::string | utils::encoding::ToHex (const void *encoded, size_t len) noexcept |
Allocates std::string, converts input and writes into said string. | |
size_t | utils::encoding::FromHex (std::string_view encoded, std::string &out) noexcept |
Converts as much of input from hex as possible and writes data into out . | |
std::string | utils::encoding::FromHex (std::string_view encoded) noexcept |
This FromHex overload allocates string and calls FromHex; if data is not fully a hex string, then it will be only partially processed. | |
std::string_view | utils::encoding::GetHexPart (std::string_view encoded) noexcept |
bool | utils::encoding::IsHexData (std::string_view encoded) noexcept |
Checks that given range is fully a hex string. That is, if passed to FromHex, it will be fully processed. | |
std::string | utils::encoding::ToHexString (uint64_t value) |
iterprets uint64_t value as array of bytes and applies ToHex to it | |
constexpr size_t | utils::encoding::LengthInHexForm (size_t size) noexcept |
Calculate expected length of input after being hex encoded. | |
constexpr size_t | utils::encoding::LengthInHexForm (std::string_view data) noexcept |
|
inlinenoexcept |
|
noexcept |
Converts as much of input from hex as possible and writes data into out
.
To convert some range from hex, range must have even number of elements and every element must be hex character. To avoid throwing, algorithms consumes as much data as possible and returns how much it was able to process
encoded | input range to convert |
out | Result will be written into out. Previous value will be cleared. |
|
constexprnoexcept |
Return upper limit on number of characters required to unhex input of given size.
For example:
|
noexcept |
Returns range that constitutes hex string - e.g. sub-view of encoded that could be fully interpreted as hex string. Basically, if you have string_view a
and c = GetHexPart(a), then range FromHex(c) will be fully parsed.
encoded | input array of bytes. |
|
constexprnoexcept |
|
constexprnoexcept |
|
inlinenoexcept |
|
noexcept |
Converts input to hex and writes data to output out
.
input | bytes to convert |
out | string to write data. out will be cleared |
char utils::encoding::ToHexChar | ( | int | num | ) |
Converts number to hex character; number must be within range [0,16)
out_of_bounds | exception if num is out of range |