6#include <unordered_map>
8#include <userver/storages/postgres/detail/is_decl_complete.hpp>
9#include <userver/storages/postgres/io/pg_types.hpp>
10#include <userver/utils/void_t.hpp>
12USERVER_NAMESPACE_BEGIN
42BufferCategory GetTypeBufferCategory(
const TypeBufferCategory&, Oid);
47 return std::hash<IntegerType>{}(
static_cast<IntegerType>(val));
51inline constexpr int kPgBinaryDataFormat = 1;
57 static constexpr std::size_t npos = std::numeric_limits<std::size_t>::max();
61 std::size_t length = 0;
62 const std::uint8_t* buffer =
nullptr;
64 std::string ToString()
const {
65 return {
reinterpret_cast<
const char*>(buffer), length};
68 std::size_t offset, std::size_t size = npos,
72 std::size_t Read(T&& value,
74 std::size_t length =
sizeof(T));
76 std::size_t Read(T&& value,
const TypeBufferCategory& categories,
77 std::size_t length =
sizeof(T),
82 std::size_t ReadRaw(T&& value,
const TypeBufferCategory& categories,
88template <
typename T,
typename Enable = USERVER_NAMESPACE::utils::void_t<>>
93template <
typename T,
typename Enable = USERVER_NAMESPACE::utils::void_t<>>
94struct BufferFormatter;
99template <
typename T,
typename Enable = USERVER_NAMESPACE::
utils::
void_t<>>
105template <
typename T,
typename Enable = USERVER_NAMESPACE::
utils::
void_t<>>
130inline constexpr bool kHasParser = HasParser<T>::value;
132inline constexpr bool kHasFormatter = HasFormatter<T>::value;
136constexpr bool CheckParser() {
137 static_assert(kHasParser<T> || std::is_enum_v<T>,
138 "Type doesn't have a parser. Probably you forgot to include "
139 "file with parser or to define your own. Please see page "
140 "`uPg: Supported data types` for more information");
142 static_assert(kHasParser<T> || !std::is_enum_v<T>,
143 "Type doesn't have a parser. Probably you forgot to include "
144 "file with parser, to define your own or to specialize "
145 "`storages::postgres::io::traits::CanUseEnumAsStrongTypedef`. "
146 "See page `uPg: Supported data types` for more information");
152constexpr void CheckFormatter() {
153 static_assert(kHasFormatter<T> || std::is_enum_v<T>,
154 "Type doesn't have a formatter. Probably you forgot to include "
155 "file with formatter or to define your own. Please see page "
156 "`uPg: Supported data types` for more information");
158 static_assert(kHasFormatter<T> || !std::is_enum_v<T>,
159 "Type doesn't have a formatter. Probably you forgot to include "
160 "file with formatter, to define your own or to specialize "
161 "`storages::postgres::io::traits::CanUseEnumAsStrongTypedef`. "
162 "See page `uPg: Supported data types` for more information");
172inline constexpr BufferCategory kParserBufferCategory =
173 ParserBufferCategory<T>::value;
179constexpr auto DetectBufferCategory() {
180 if constexpr (kHasParser<T>) {
181 return ParserBufferCategoryType<
typename IO<T>::ParserType>{};
183 return BufferCategoryConstant<BufferCategory::kNoParser>{};
190inline constexpr BufferCategory kTypeBufferCategory =
191 TypeBufferCategory<T>::value;
197struct CustomParserDefined : utils::IsDeclComplete<BufferParser<T>> {};
199inline constexpr bool kCustomParserDefined = CustomParserDefined<T>::value;
202struct CustomFormatterDefined : utils::IsDeclComplete<BufferFormatter<T>> {};
204inline constexpr bool kCustomFormatterDefined =
205 CustomFormatterDefined<T>::value;