3#include <userver/storages/postgres/io/buffer_io.hpp>
4#include <userver/storages/postgres/io/buffer_io_base.hpp>
5#include <userver/storages/postgres/io/field_buffer.hpp>
6#include <userver/storages/postgres/io/type_traits.hpp>
7#include <userver/storages/postgres/io/user_types.hpp>
9#include <userver/utils/assert.hpp>
11USERVER_NAMESPACE_BEGIN
17template <
typename UserType,
typename WireType,
typename Converter,
19struct TransformParserBase : BufferParserBase<UserType> {
20 using BaseType = BufferParserBase<UserType>;
21 using BaseType::BaseType;
25 io::ReadBuffer(buffer, tmp);
26 this->value = Converter{}(tmp);
30template <
typename UserType,
typename WireType,
typename Converter>
31struct TransformParserBase<UserType, WireType, Converter,
true>
32 : BufferParserBase<UserType> {
33 using BaseType = BufferParserBase<UserType>;
34 using BaseType::BaseType;
37 const TypeBufferCategory& categories) {
39 io::ReadBuffer(buffer, tmp, categories);
40 this->value = Converter{}(tmp);
46template <
typename UserType,
typename WireType,
typename Converter>
48 UserType, WireType, Converter,
49 detail::kParserRequiresTypeCategories<WireType>> {
50 using BaseType = detail::TransformParserBase<
51 UserType, WireType, Converter,
52 detail::kParserRequiresTypeCategories<WireType>>;
53 using BaseType::BaseType;
56template <
typename UserType,
typename WireType,
typename Converter>
58 using BaseType = detail::BufferFormatterBase<UserType>;
59 using BaseType::BaseType;
61 template <
typename Buffer>
62 void operator()(
const UserTypes& types, Buffer& buffer)
const {
63 if constexpr (
traits::kIsMappedToSystemType<UserType> &&
64 traits::kIsMappedToSystemType<WireType>) {
65 static_assert(CppToPg<UserType>::type_oid == CppToPg<WireType>::type_oid,
66 "Database type mismatch in TransformFormatter");
69 CppToPg<UserType>::GetOid(types) == CppToPg<WireType>::GetOid(types),
70 "Database type mismatch in TransformFormatter");
72 WireType tmp = Converter{}(
this->value);
73 io::WriteBuffer(types, buffer, tmp);