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;
123struct HasParser : utils::IsDeclComplete<
typename IO<T>::ParserType> {};
132inline constexpr bool kHasParser = HasParser<T>::value;
134inline constexpr bool kHasFormatter = HasFormatter<T>::value;
138constexpr bool CheckParser() {
140 kHasParser<T> || std::is_enum_v<T>,
141 "Type doesn't have a parser. Probably you forgot to include "
142 "file with parser or to define your own. Please see page "
143 "`uPg: Supported data types` for more information"
147 kHasParser<T> || !std::is_enum_v<T>,
148 "Type doesn't have a parser. Probably you forgot to include "
149 "file with parser, to define your own or to specialize "
150 "`storages::postgres::io::traits::CanUseEnumAsStrongTypedef`. "
151 "See page `uPg: Supported data types` for more information"
158constexpr void CheckFormatter() {
160 kHasFormatter<T> || std::is_enum_v<T>,
161 "Type doesn't have a formatter. Probably you forgot to include "
162 "file with formatter or to define your own. Please see page "
163 "`uPg: Supported data types` for more information"
167 kHasFormatter<T> || !std::is_enum_v<T>,
168 "Type doesn't have a formatter. Probably you forgot to include "
169 "file with formatter, to define your own or to specialize "
170 "`storages::postgres::io::traits::CanUseEnumAsStrongTypedef`. "
171 "See page `uPg: Supported data types` for more information"
181inline constexpr BufferCategory kParserBufferCategory = ParserBufferCategory<T>::value;
187constexpr auto DetectBufferCategory() {
188 if constexpr (kHasParser<T>) {
189 return ParserBufferCategoryType<
typename IO<T>::ParserType>{};
198inline constexpr BufferCategory kTypeBufferCategory = TypeBufferCategory<T>::value;
204struct CustomParserDefined : utils::IsDeclComplete<BufferParser<T>> {};
206inline constexpr bool kCustomParserDefined = CustomParserDefined<T>::value;
209struct CustomFormatterDefined : utils::IsDeclComplete<BufferFormatter<T>> {};
211inline constexpr bool kCustomFormatterDefined = CustomFormatterDefined<T>::value;