userver
C++ Async Framework
Toggle main menu visibility
Loading...
Searching...
No Matches
macaddr.hpp
Go to the documentation of this file.
1
#
pragma
once
2
3
/// @file userver/storages/postgres/io/macaddr.hpp
4
/// @brief utils::Macaddr and utils::Macaddr8 I/O support
5
/// @ingroup userver_postgres_parse_and_format
6
7
#
include
<
userver
/
storages
/
postgres
/
exceptions
.
hpp
>
8
#
include
<
userver
/
storages
/
postgres
/
io
/
buffer_io
.
hpp
>
9
#
include
<
userver
/
storages
/
postgres
/
io
/
buffer_io_base
.
hpp
>
10
#
include
<
userver
/
utils
/
macaddr
.
hpp
>
11
12
USERVER_NAMESPACE_BEGIN
13
14
namespace
storages::
postgres
{
15
16
using
Macaddr = USERVER_NAMESPACE::
utils
::
Macaddr
;
17
using
Macaddr8 = USERVER_NAMESPACE::
utils
::
Macaddr8
;
18
19
namespace
io
{
20
namespace
detail {
21
22
template
<
typename
T>
23
struct
MacaddrFormatterBase : BufferFormatterBase<T> {
24
using
BaseType = BufferFormatterBase<T>;
25
26
using
BaseType::BaseType;
27
28
template
<
typename
Buffer>
29
void
operator()(
const
UserTypes
& types, Buffer& buffer) {
30
for
(
const
auto
val :
this
->value.GetOctets()) {
31
io
::WriteBuffer(types, buffer,
static_cast
<
char
>(val));
32
}
33
}
34
};
35
36
template
<
typename
T>
37
struct
MacaddrBufferParser : BufferParserBase<T> {
38
using
BaseType = BufferParserBase<T>;
39
using
BaseType::BaseType;
40
void
operator()(
FieldBuffer
buffer) {
41
typename
T::OctetsType octets;
42
// The buffer is server-supplied; reject a short one before reading the
43
// fixed number of octets straight from it.
44
if
(buffer.length < octets.size()) {
45
throw
storages::
postgres
::
InvalidInputBufferSize
(
46
fmt::format(
"Buffer size {} is too small for a MAC address of {} bytes"
, buffer.length, octets.size())
47
);
48
}
49
const
uint8_t* byte_cptr = buffer.buffer;
50
for
(
auto
& val : octets) {
51
val = *byte_cptr;
52
++byte_cptr;
53
}
54
this
->value = T(octets);
55
}
56
};
57
58
}
// namespace detail
59
60
///@brief Binary formatter for utils::macaddr:Macaddr
61
template
<>
62
struct
BufferFormatter
<Macaddr> : detail::MacaddrFormatterBase<Macaddr> {
63
using
BaseType = detail::MacaddrFormatterBase<Macaddr>;
64
65
using
BaseType::BaseType;
66
};
67
68
///@brief Binary formatter for utils::macaddr:Macaddr8
69
template
<>
70
struct
BufferFormatter
<Macaddr8> : detail::MacaddrFormatterBase<Macaddr8> {
71
using
BaseType = detail::MacaddrFormatterBase<Macaddr8>;
72
73
using
BaseType::BaseType;
74
};
75
76
/// @brief Binary parser for utils::macaddr::Macaddr
77
template
<>
78
struct
BufferParser
<Macaddr> : detail::MacaddrBufferParser<Macaddr> {
79
using
BaseType = detail::MacaddrBufferParser<Macaddr>;
80
81
using
BaseType::BaseType;
82
};
83
84
/// @brief Binary parser for utils::macaddr::Macaddr8
85
template
<>
86
struct
BufferParser
<Macaddr8> : detail::MacaddrBufferParser<Macaddr8> {
87
using
BaseType = detail::MacaddrBufferParser<Macaddr8>;
88
89
using
BaseType::BaseType;
90
};
91
92
template
<>
93
struct
CppToSystemPg
<Macaddr> : PredefinedOid<
PredefinedOids
::kMacaddr> {};
94
95
template
<>
96
struct
CppToSystemPg
<Macaddr8> : PredefinedOid<
PredefinedOids
::kMacaddr8> {};
97
98
}
// namespace io
99
}
// namespace storages::postgres
100
101
USERVER_NAMESPACE_END
userver
storages
postgres
io
macaddr.hpp
Generated on
for userver by
Doxygen
1.17.0