userver
C++ Async Framework
Toggle main menu visibility
Loading...
Searching...
No Matches
hex.hpp
Go to the documentation of this file.
1
#pragma once
2
6
7
#include <cstdint>
8
#include <string>
9
10
#include <
userver/utils/span.hpp
>
11
12
USERVER_NAMESPACE_BEGIN
13
15
namespace
utils::encoding
{
16
19
char
ToHexChar
(
int
num);
20
23
24
constexpr
size_t
LengthInHexForm
(
size_t
size)
noexcept
{
return
size * 2; }
25
26
constexpr
size_t
LengthInHexForm
(std::string_view data)
noexcept
{
27
return
USERVER_NAMESPACE::utils::encoding::LengthInHexForm(data.size());
28
}
30
40
constexpr
size_t
FromHexUpperBound
(
size_t
size)
noexcept
{
41
// Although only even-sized input is valid, we have to support an odd
42
// number is well. Luckily for us, size / 2 will get us correct value
43
// anyway
44
return
size / 2;
45
}
46
50
void
ToHex
(std::string_view input, std::string& out)
noexcept
;
51
56
void
ToHexBuffer
(std::string_view input,
utils::span<char>
out)
noexcept
;
57
60
inline
std::string
ToHex
(std::string_view data)
noexcept
{
61
std::string result;
62
USERVER_NAMESPACE::utils::encoding::ToHex(data, result);
63
return
result;
64
}
65
69
inline
std::string
ToHex
(
const
void
* encoded,
size_t
len)
noexcept
{
70
const
auto
* chars =
reinterpret_cast<
const
char
*
>
(encoded);
71
return
USERVER_NAMESPACE::utils::encoding::ToHex(std::string_view{chars, len});
72
}
73
85
size_t
FromHex
(std::string_view encoded, std::string& out)
noexcept
;
86
89
inline
std::string
FromHex
(std::string_view encoded)
noexcept
{
90
std::string result;
91
USERVER_NAMESPACE::utils::encoding::FromHex(encoded, result);
92
return
result;
93
}
94
100
std::string_view
GetHexPart
(std::string_view encoded)
noexcept
;
101
104
bool
IsHexData
(std::string_view encoded)
noexcept
;
105
107
inline
std::string
ToHexString
(uint64_t value) {
108
return
USERVER_NAMESPACE::utils::encoding::ToHex(&value,
sizeof
(value));
109
}
110
111
}
// namespace utils::encoding
112
113
USERVER_NAMESPACE_END
userver
utils
encoding
hex.hpp
Generated on
for userver by
Doxygen
1.17.0