6#include <unordered_map>
8#include <userver/storages/postgres/detail/is_decl_complete.hpp>
9#include <userver/storages/postgres/io/pg_types.hpp>
11USERVER_NAMESPACE_BEGIN
37using BufferCategoryConstant = std::integral_constant<
BufferCategory, Category>;
41BufferCategory GetTypeBufferCategory(
const TypeBufferCategory&, Oid);
45 std::size_t operator()(
BufferCategory val)
const {
return std::hash<IntegerType>{}(
static_cast<IntegerType>(val)); }
48inline constexpr int kPgBinaryDataFormat = 1;
54 static constexpr std::size_t npos = std::numeric_limits<std::size_t>::max();
58 std::size_t length = 0;
59 const std::uint8_t* buffer =
nullptr;
61 std::string ToString()
const {
return {
reinterpret_cast<
const char*>(buffer), length}; }
64 std::size_t size = npos,
73 const TypeBufferCategory& categories,
74 std::size_t length =
sizeof(T),
82 const TypeBufferCategory& categories,
95struct BufferFormatter;
102 using type = BufferParser<T>;
108 using type = BufferFormatter<T>;
116 using ParserType =
typename Input<T>::type;
117 using FormatterType =
typename Output<T>::type;
122concept HasParser = utils::IsDeclComplete<
typename IO<T>::ParserType>::value;
126concept HasFormatter = utils::IsDeclComplete<
typename IO<T>::FormatterType>::value;
129constexpr bool CheckParser() {
131 HasParser<T> || std::is_enum_v<T>,
132 "Type doesn't have a parser. Probably you forgot to include "
133 "file with parser or to define your own. Please see page "
134 "`uPg: Supported data types` for more information"
138 HasParser<T> || !std::is_enum_v<T>,
139 "Type doesn't have a parser. Probably you forgot to include "
140 "file with parser, to define your own or to specialize "
141 "`storages::postgres::io::traits::CanUseEnumAsStrongTypedef`. "
142 "See page `uPg: Supported data types` for more information"
149constexpr void CheckFormatter() {
151 HasFormatter<T> || std::is_enum_v<T>,
152 "Type doesn't have a formatter. Probably you forgot to include "
153 "file with formatter or to define your own. Please see page "
154 "`uPg: Supported data types` for more information"
158 HasFormatter<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 = ParserBufferCategory<T>::value;
178constexpr auto DetectBufferCategory() {
179 if constexpr (HasParser<T>) {
180 return ParserBufferCategoryType<
typename IO<T>::ParserType>{};
189inline constexpr BufferCategory kTypeBufferCategory = TypeBufferCategory<T>::value;
195concept CustomParserDefined = utils::IsDeclComplete<BufferParser<T>>::value;
198concept CustomFormatterDefined = utils::IsDeclComplete<BufferFormatter<T>>::value;