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,
bool Categories>
18struct TransformParserBase : BufferParserBase<UserType> {
19 using BaseType = BufferParserBase<UserType>;
20 using BaseType::BaseType;
24 io::ReadBuffer(buffer, tmp);
25 this->value = Converter{}(tmp);
29template <
typename UserType,
typename WireType,
typename Converter>
30struct TransformParserBase<UserType, WireType, Converter,
true> : BufferParserBase<UserType> {
31 using BaseType = BufferParserBase<UserType>;
32 using BaseType::BaseType;
34 void operator()(
const FieldBuffer& buffer,
const TypeBufferCategory& categories) {
36 io::ReadBuffer(buffer, tmp, categories);
37 this->value = Converter{}(tmp);
43template <
typename UserType,
typename WireType,
typename Converter>
45 : detail::TransformParserBase<UserType, WireType, Converter, detail::kParserRequiresTypeCategories<WireType>> {
47 detail::TransformParserBase<UserType, WireType, Converter, detail::kParserRequiresTypeCategories<WireType>>;
48 using BaseType::BaseType;
51template <
typename UserType,
typename WireType,
typename Converter>
53 using BaseType = detail::BufferFormatterBase<UserType>;
54 using BaseType::BaseType;
56 template <
typename Buffer>
57 void operator()(
const UserTypes& types, Buffer& buffer)
const {
58 if constexpr (
traits::kIsMappedToSystemType<UserType> &&
traits::kIsMappedToSystemType<WireType>) {
60 CppToPg<UserType>::type_oid == CppToPg<WireType>::type_oid,
61 "Database type mismatch in TransformFormatter"
65 CppToPg<UserType>::GetOid(types) == CppToPg<WireType>::GetOid(types),
66 "Database type mismatch in TransformFormatter"
69 WireType tmp = Converter{}(
this->value);
70 io::WriteBuffer(types, buffer, tmp);