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
38using BufferCategoryConstant = std::integral_constant<
BufferCategory, Category>;
42BufferCategory GetTypeBufferCategory(
const TypeBufferCategory&, Oid);
46 std::size_t operator()(
BufferCategory val)
const {
return std::hash<IntegerType>{}(
static_cast<IntegerType>(val)); }
49inline constexpr int kPgBinaryDataFormat = 1;
55 static constexpr std::size_t npos = std::numeric_limits<std::size_t>::max();
59 std::size_t length = 0;
60 const std::uint8_t* buffer =
nullptr;
62 std::string ToString()
const {
return {
reinterpret_cast<
const char*>(buffer), length}; }
65 std::size_t size = npos,
74 const TypeBufferCategory& categories,
75 std::size_t length =
sizeof(T),
83 const TypeBufferCategory& categories,
90template <
typename T,
typename Enable = USERVER_NAMESPACE::
utils::void_t<>>
95template <
typename T,
typename Enable = USERVER_NAMESPACE::
utils::void_t<>>
96struct BufferFormatter;
101template <
typename T,
typename Enable = USERVER_NAMESPACE::
utils::void_t<>>
103 using type = BufferParser<T>;
107template <
typename T,
typename Enable = USERVER_NAMESPACE::
utils::void_t<>>
109 using type = BufferFormatter<T>;
117 using ParserType =
typename Input<T>::type;
118 using FormatterType =
typename Output<T>::type;
123concept HasParser = utils::IsDeclComplete<
typename IO<T>::ParserType>::value;
127concept HasFormatter = utils::IsDeclComplete<
typename IO<T>::FormatterType>::value;
130constexpr bool CheckParser() {
132 HasParser<T> || std::is_enum_v<T>,
133 "Type doesn't have a parser. Probably you forgot to include "
134 "file with parser or to define your own. Please see page "
135 "`uPg: Supported data types` for more information"
139 HasParser<T> || !std::is_enum_v<T>,
140 "Type doesn't have a parser. Probably you forgot to include "
141 "file with parser, to define your own or to specialize "
142 "`storages::postgres::io::traits::CanUseEnumAsStrongTypedef`. "
143 "See page `uPg: Supported data types` for more information"
150constexpr void CheckFormatter() {
152 HasFormatter<T> || std::is_enum_v<T>,
153 "Type doesn't have a formatter. Probably you forgot to include "
154 "file with formatter or to define your own. Please see page "
155 "`uPg: Supported data types` for more information"
159 HasFormatter<T> || !std::is_enum_v<T>,
160 "Type doesn't have a formatter. Probably you forgot to include "
161 "file with formatter, to define your own or to specialize "
162 "`storages::postgres::io::traits::CanUseEnumAsStrongTypedef`. "
163 "See page `uPg: Supported data types` for more information"
173inline constexpr BufferCategory kParserBufferCategory = ParserBufferCategory<T>::value;
179constexpr auto DetectBufferCategory() {
180 if constexpr (HasParser<T>) {
181 return ParserBufferCategoryType<
typename IO<T>::ParserType>{};
190inline constexpr BufferCategory kTypeBufferCategory = TypeBufferCategory<T>::value;
196concept CustomParserDefined = utils::IsDeclComplete<BufferParser<T>>::value;
199concept CustomFormatterDefined = utils::IsDeclComplete<BufferFormatter<T>>::value;