9#include <boost/endian/arithmetic.hpp>
10#include <userver/storages/postgres/io/buffer_io_base.hpp>
11#include <userver/storages/postgres/io/integral_types.hpp>
12#include <userver/storages/postgres/io/traits.hpp>
13#include <userver/storages/postgres/io/type_mapping.hpp>
15USERVER_NAMESPACE_BEGIN
22struct FloatingPointType;
25struct FloatingPointType<4> {
30struct FloatingPointType<8> {
34template <std::size_t Size>
35struct FloatingPointBySizeParser {
36 using FloatType =
typename FloatingPointType<Size>::type;
37 using IntType =
typename IntegralType<Size>::type;
38 using IntParser = IntegralBySizeParser<Size>;
40 static FloatType ParseBuffer(
const FieldBuffer& buf) {
41 const IntType tmp = IntParser::ParseBuffer(buf);
42 FloatType float_value{};
43 std::memcpy(&float_value, &tmp, Size);
49struct FloatingPointBinaryParser : BufferParserBase<T> {
50 using BaseType = BufferParserBase<T>;
51 using BaseType::BaseType;
56 this->value = FloatingPointBySizeParser<4>::ParseBuffer(buf);
59 this->value = FloatingPointBySizeParser<8>::ParseBuffer(buf);
62 throw InvalidInputBufferSize{buf.length,
"for a floating point value type"};
68struct FloatingPointBinaryFormatter {
69 static constexpr std::size_t size =
sizeof(T);
72 explicit FloatingPointBinaryFormatter(T val) : value{val} {}
74 template <
typename Buffer>
75 void operator()(
const UserTypes& types, Buffer& buf)
const {
76 using IntType =
typename IntegralType<size>::type;
78 std::memcpy(&int_value, &value, size);
79 IntegralBinaryFormatter<IntType>{int_value}(types, buf);
111struct CppToSystemPg<
float> : PredefinedOid<PredefinedOids::kFloat4> {};
113struct CppToSystemPg<
double> : PredefinedOid<PredefinedOids::kFloat8> {};