userver: userver/storages/postgres/io/numeric_data.hpp Source File
Loading...
Searching...
No Matches
numeric_data.hpp
1#pragma once
2
3#include <userver/storages/postgres/io/buffer_io.hpp>
4
5USERVER_NAMESPACE_BEGIN
6
7namespace storages::postgres::io::detail {
8
9/// All digits packed in a single integer value, if the size of int64 is enough
10struct IntegralRepresentation {
11 std::int64_t value;
12 int fractional_digit_count;
13};
14
15/// A helper function to read PostgreSQL binary buffer containing a
16/// numeric/decimal to string representation
17std::string NumericBufferToString(const FieldBuffer& buffer);
18/// A helper function to write string representation of a numeric/decimal to
19/// PostgreSQL binary buffer representation
20std::string StringToNumericBuffer(const std::string& str_rep);
21
22/// A helper function to read PostgreSQL numeric/decimal binary buffer and pack
23/// the value in a single int64 value.
24/// @throw NumericOverflow if the int64 is not enough to represent value in the
25/// buffer
26/// @throw ValueIsNaN if the value in the buffer is NaN
27IntegralRepresentation NumericBufferToInt64(const FieldBuffer& buffer);
28/// A helper function to write PostgreSQL numeric/decimal binary buffer using
29/// a value packed into a single int64 value.
30/// @throw InvalidRepresentation if the dec_digits field of binary
31/// representation is unreasonable
32std::string Int64ToNumericBuffer(const IntegralRepresentation& rep);
33
34} // namespace storages::postgres::io::detail
35
36USERVER_NAMESPACE_END