Encoders, decoders and helpers for hexadecimal representations.
Definition in file hex.hpp.
Go to the source code of this file.
#include <cstdint>
#include <string>
|
namespace | utils |
| Utilities.
|
|
◆ FromHex() [1/2]
std::string utils::encoding::FromHex |
( |
std::string_view | encoded | ) |
|
|
inlinenoexcept |
This FromHex overload allocates string and calls FromHex; if data is not fully a hex string, then it will be only partially processed.
Definition at line 80 of file hex.hpp.
◆ FromHex() [2/2]
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
.
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
- Parameters
-
encoded | input range to convert |
out | Result will be written into out. Previous value will be cleared. |
- Returns
- Number of characters successfully parsed.
◆ FromHexUpperBound()
constexpr size_t utils::encoding::FromHexUpperBound |
( |
size_t | size | ) |
|
|
constexprnoexcept |
Return upper limit on number of characters required to unhex input of given size.
For example:
- FromHexUpperBound(1) = 0, because you can't really unhex one char, it is only half byte. Where is the second half?
- FromHexUpperBound(2) = 1. Two chars will be converted into one byte
- FromHexUpperBound(5) = 2. First 4 chars will be unhexed into 2 bytes, and there will be one left.
Definition at line 37 of file hex.hpp.
◆ GetHexPart()
std::string_view utils::encoding::GetHexPart |
( |
std::string_view | encoded | ) |
|
|
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.
- Parameters
-
encoded | input array of bytes. |
◆ LengthInHexForm() [1/2]
constexpr size_t utils::encoding::LengthInHexForm |
( |
size_t | size | ) |
|
|
constexprnoexcept |
Calculate expected length of input after being hex encoded.
Definition at line 21 of file hex.hpp.
◆ LengthInHexForm() [2/2]
constexpr size_t utils::encoding::LengthInHexForm |
( |
std::string_view | data | ) |
|
|
constexprnoexcept |
◆ ToHex() [1/3]
std::string utils::encoding::ToHex |
( |
const void * | encoded, |
|
|
size_t | len ) |
|
inlinenoexcept |
Allocates std::string, converts input and writes into said string.
- Parameters
-
data | start of continuous range in memory |
len | size of that range |
Definition at line 60 of file hex.hpp.
◆ ToHex() [2/3]
std::string utils::encoding::ToHex |
( |
std::string_view | data | ) |
|
|
inlinenoexcept |
Allocates std::string, converts input and writes into said string.
- Parameters
-
input | range of input bytes |
Definition at line 51 of file hex.hpp.
◆ ToHex() [3/3]
void utils::encoding::ToHex |
( |
std::string_view | input, |
|
|
std::string & | out ) |
|
noexcept |
Converts input to hex and writes data to output out
.
- Parameters
-
input | bytes to convert |
out | string to write data. out will be cleared |
◆ ToHexChar()
char utils::encoding::ToHexChar |
( |
int | num | ) |
|
Converts number to hex character; number must be within range [0,16)
- Exceptions
-
out_of_bounds | exception if num is out of range |
◆ ToHexString()
std::string utils::encoding::ToHexString |
( |
uint64_t | value | ) |
|
|
inline |
iterprets uint64_t value as array of bytes and applies ToHex to it
Definition at line 98 of file hex.hpp.