8#include <userver/storages/postgres/exceptions.hpp> 
    9#include <userver/storages/postgres/io/buffer_io_base.hpp> 
   10#include <userver/storages/postgres/io/field_buffer.hpp> 
   11#include <userver/storages/postgres/io/floating_point_types.hpp> 
   12#include <userver/storages/postgres/io/traits.hpp> 
   13#include <userver/storages/postgres/io/type_mapping.hpp> 
   14#include <userver/storages/postgres/io/type_traits.hpp> 
   15#include <userver/storages/postgres/io/user_types.hpp> 
   17USERVER_NAMESPACE_BEGIN
 
   28  constexpr bool operator==(
const Point& rhs) 
const {
 
   29    return x == rhs.x && y == rhs.y;
 
   31  constexpr bool operator!=(
const Point& rhs) 
const { 
return !(*
this == rhs); }
 
   38  constexpr bool operator==(
const LineSegment& rhs) 
const {
 
   39    return ends[0] == rhs.ends[0] && ends[1] == rhs.ends[1];
 
   41  constexpr bool operator!=(
const LineSegment& rhs) 
const {
 
   42    return !(*
this == rhs);
 
   45  std::array<Point, 2> ends{};
 
   50  constexpr bool operator==(
const Line& rhs) 
const {
 
   51    return a == rhs.a && b == rhs.b && c == rhs.c;
 
   53  constexpr bool operator!=(
const Line& rhs) 
const { 
return !(*
this == rhs); }
 
   61  constexpr bool operator==(
const Box& rhs) 
const {
 
   62    return corners[0] == rhs.corners[0] && corners[1] == rhs.corners[1];
 
   64  constexpr bool operator!=(
const Box& rhs) 
const { 
return !(*
this == rhs); }
 
   66  std::array<Point, 2> corners{};
 
   70  bool operator==(
const Path& rhs) 
const {
 
   71    return is_closed == rhs.is_closed && points == rhs.points;
 
   73  bool operator!=(
const Path& rhs) 
const { 
return !(*
this == rhs); }
 
   75  bool is_closed{
false};
 
   76  std::vector<Point> points;
 
   80  bool operator==(
const Polygon& rhs) 
const { 
return points == rhs.points; }
 
   81  bool operator!=(
const Polygon& rhs) 
const { 
return !(*
this == rhs); }
 
   83  std::vector<Point> points;
 
   87  constexpr bool operator==(
const Circle& rhs) 
const {
 
   88    return center == rhs.center && radius == rhs.radius;
 
   90  constexpr bool operator!=(
const Circle& rhs) 
const { 
return !(*
this == rhs); }
 
   97struct PointParser : BufferParserBase<Point> {
 
   98  using BaseType = BufferParserBase<Point>;
 
   99  using BaseType::BaseType;
 
  102    buffer.Read(value.x);
 
  103    buffer.Read(value.y);
 
  107struct PointFormatter : BufferFormatterBase<Point> {
 
  108  using BaseType = BufferFormatterBase<Point>;
 
  109  using BaseType::BaseType;
 
  111  template <
typename Buffer>
 
  112  void operator()(
const UserTypes& types, Buffer& buffer) 
const {
 
  113    io::WriteBuffer(types, buffer, value.x);
 
  114    io::WriteBuffer(types, buffer, value.y);
 
  118struct LineSegmentParser : BufferParserBase<LineSegment> {
 
  119  using BaseType = BufferParserBase<LineSegment>;
 
  120  using BaseType::BaseType;
 
  123    buffer.Read(value.ends[0]);
 
  124    buffer.Read(value.ends[1]);
 
  128struct LineSegmentFormatter : BufferFormatterBase<LineSegment> {
 
  129  using BaseType = BufferFormatterBase<LineSegment>;
 
  130  using BaseType::BaseType;
 
  132  template <
typename Buffer>
 
  133  void operator()(
const UserTypes& types, Buffer& buffer) 
const {
 
  134    io::WriteBuffer(types, buffer, value.ends[0]);
 
  135    io::WriteBuffer(types, buffer, value.ends[1]);
 
  139struct LineParser : BufferParserBase<Line> {
 
  140  using BaseType = BufferParserBase<Line>;
 
  141  using BaseType::BaseType;
 
  144    buffer.Read(value.a);
 
  145    buffer.Read(value.b);
 
  146    buffer.Read(value.c);
 
  150struct LineFormatter : BufferFormatterBase<Line> {
 
  151  using BaseType = BufferFormatterBase<Line>;
 
  152  using BaseType::BaseType;
 
  154  template <
typename Buffer>
 
  155  void operator()(
const UserTypes& types, Buffer& buffer) 
const {
 
  156    io::WriteBuffer(types, buffer, value.a);
 
  157    io::WriteBuffer(types, buffer, value.b);
 
  158    io::WriteBuffer(types, buffer, value.c);
 
  162struct BoxParser : BufferParserBase<Box> {
 
  163  using BaseType = BufferParserBase<Box>;
 
  164  using BaseType::BaseType;
 
  167    buffer.Read(value.corners[0]);
 
  168    buffer.Read(value.corners[1]);
 
  172struct BoxFormatter : BufferFormatterBase<Box> {
 
  173  using BaseType = BufferFormatterBase<Box>;
 
  174  using BaseType::BaseType;
 
  176  template <
typename Buffer>
 
  177  void operator()(
const UserTypes& types, Buffer& buffer) 
const {
 
  178    io::WriteBuffer(types, buffer, value.corners[0]);
 
  179    io::WriteBuffer(types, buffer, value.corners[1]);
 
  183struct PathParser : BufferParserBase<Path> {
 
  184  using BaseType = BufferParserBase<Path>;
 
  185  using BaseType::BaseType;
 
  188    buffer.Read(value.is_closed);
 
  190    buffer.Read(point_no);
 
  191    value.points.resize(point_no);
 
  192    for (
auto i = 0; i < point_no; ++i) {
 
  193      buffer.Read(value.points[i]);
 
  198struct PathFormatter : BufferFormatterBase<Path> {
 
  199  using BaseType = BufferFormatterBase<Path>;
 
  200  using BaseType::BaseType;
 
  202  template <
typename Buffer>
 
  203  void operator()(
const UserTypes& types, Buffer& buffer) 
const {
 
  204    io::WriteBuffer(types, buffer, value.is_closed);
 
  205    Integer points_no = value.points.size();
 
  206    io::WriteBuffer(types, buffer, points_no);
 
  207    for (
const auto& p : value.points) {
 
  208      io::WriteBuffer(types, buffer, p);
 
  213struct PolygonParser : BufferParserBase<Polygon> {
 
  214  using BaseType = BufferParserBase<Polygon>;
 
  215  using BaseType::BaseType;
 
  219    buffer.Read(point_no);
 
  220    value.points.resize(point_no);
 
  221    for (
auto i = 0; i < point_no; ++i) {
 
  222      buffer.Read(value.points[i]);
 
  227struct PolygonFormatter : BufferFormatterBase<Polygon> {
 
  228  using BaseType = BufferFormatterBase<Polygon>;
 
  229  using BaseType::BaseType;
 
  231  template <
typename Buffer>
 
  232  void operator()(
const UserTypes& types, Buffer& buffer) 
const {
 
  233    Integer points_no = value.points.size();
 
  234    io::WriteBuffer(types, buffer, points_no);
 
  235    for (
const auto& p : value.points) {
 
  236      io::WriteBuffer(types, buffer, p);
 
  241struct CircleParser : BufferParserBase<Circle> {
 
  242  using BaseType = BufferParserBase<Circle>;
 
  243  using BaseType::BaseType;
 
  246    buffer.Read(value.center);
 
  247    buffer.Read(value.radius);
 
  251struct CircleFormatter : BufferFormatterBase<Circle> {
 
  252  using BaseType = BufferFormatterBase<Circle>;
 
  253  using BaseType::BaseType;
 
  255  template <
typename Buffer>
 
  256  void operator()(
const UserTypes& types, Buffer& buffer) 
const {
 
  257    io::WriteBuffer(types, buffer, value.center);
 
  258    io::WriteBuffer(types, buffer, value.radius);
 
  367struct CppToSystemPg<detail::Point> : PredefinedOid<PredefinedOids::kPoint> {};
 
  369struct CppToSystemPg<detail::LineSegment>
 
  370    : PredefinedOid<PredefinedOids::kLseg> {};
 
  372struct CppToSystemPg<detail::Line> : PredefinedOid<PredefinedOids::kLine> {};
 
  374struct CppToSystemPg<detail::Box> : PredefinedOid<PredefinedOids::kBox> {};
 
  376struct CppToSystemPg<detail::Path> : PredefinedOid<PredefinedOids::kPath> {};
 
  378struct CppToSystemPg<detail::Polygon>
 
  379    : PredefinedOid<PredefinedOids::kPolygon> {};
 
  381struct CppToSystemPg<detail::Circle> : PredefinedOid<PredefinedOids::kCircle> {