userver: userver/storages/postgres/io/macaddr.hpp Source File
⚠️ This is the documentation for an old userver version. Click here to switch to the latest version.
All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Modules Pages Concepts
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/io/buffer_io.hpp>
8#include <userver/storages/postgres/io/buffer_io_base.hpp>
9#include <userver/utils/macaddr.hpp>
10
11USERVER_NAMESPACE_BEGIN
12
13namespace storages::postgres {
14
15using Macaddr = USERVER_NAMESPACE::utils::Macaddr;
16using Macaddr8 = USERVER_NAMESPACE::utils::Macaddr8;
17
18namespace io {
19namespace detail {
20
21template <typename T>
22struct MacaddrFormatterBase : BufferFormatterBase<T> {
23 using BaseType = BufferFormatterBase<T>;
24
25 using BaseType::BaseType;
26
27 template <typename Buffer>
28 void operator()(const UserTypes& types, Buffer& buffer) {
29 for (const auto val : this->value.GetOctets()) {
30 io::WriteBuffer(types, buffer, static_cast<char>(val));
31 }
32 }
33};
34
35template <typename T>
36struct MacaddrBufferParser : BufferParserBase<T> {
37 using BaseType = BufferParserBase<T>;
38 using BaseType::BaseType;
39 void operator()(FieldBuffer buffer) {
40 typename T::OctetsType octets;
41 const uint8_t* byte_cptr = buffer.buffer;
42 for (auto& val : octets) {
43 val = *byte_cptr;
44 ++byte_cptr;
45 }
46 this->value = T(octets);
47 }
48};
49
50} // namespace detail
51
52///@brief Binary formatter for utils::macaddr:Macaddr
53template <>
56
57 using BaseType::BaseType;
58};
59
60///@brief Binary formatter for utils::macaddr:Macaddr8
61template <>
64
65 using BaseType::BaseType;
66};
67
68/// @brief Binary parser for utils::macaddr::Macaddr
69template <>
72
73 using BaseType::BaseType;
74};
75
76/// @brief Binary parser for utils::macaddr::Macaddr8
77template <>
80
81 using BaseType::BaseType;
82};
83
84template <>
85struct CppToSystemPg<Macaddr> : PredefinedOid<PredefinedOids::kMacaddr> {};
86
87template <>
88struct CppToSystemPg<Macaddr8> : PredefinedOid<PredefinedOids::kMacaddr8> {};
89
90} // namespace io
91} // namespace storages::postgres
92
93USERVER_NAMESPACE_END