userver
C++ Async Framework
Toggle main menu visibility
Loading...
Searching...
No Matches
json_types.hpp
Go to the documentation of this file.
1
#
pragma
once
2
3
/// @file userver/storages/postgres/io/json_types.hpp
4
/// @brief JSON I/O support
5
/// @ingroup userver_postgres_parse_and_format
6
7
#
include
<
type_traits
>
8
9
#
include
<
userver
/
storages
/
postgres
/
exceptions
.
hpp
>
10
#
include
<
userver
/
storages
/
postgres
/
io
/
buffer_io_base
.
hpp
>
11
#
include
<
userver
/
storages
/
postgres
/
io
/
field_buffer
.
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
>
16
17
#
include
<
userver
/
formats
/
json
.
hpp
>
18
#
include
<
userver
/
utils
/
strong_typedef
.
hpp
>
19
20
USERVER_NAMESPACE_BEGIN
21
22
namespace
storages::
postgres
{
23
24
using
PlainJson
= USERVER_NAMESPACE::
utils
::
StrongTypedef
<
25
struct
PlainJsonTag,
26
formats::
json
::
Value
,
27
USERVER_NAMESPACE::
utils
::StrongTypedefOps::kCompareTransparent>;
28
29
namespace
io
{
30
namespace
detail {
31
32
inline
constexpr
char
kJsonbVersion = 1;
33
34
struct
JsonParser : BufferParserBase<formats::
json
::
Value
> {
35
using
BaseType = BufferParserBase<formats::
json
::
Value
>;
36
using
BaseType::BaseType;
37
38
void
operator()(
const
FieldBuffer
& buffer);
39
};
40
41
void
JsonValueToBuffer(
const
formats::
json
::
Value
& value, std::vector<
char
>& buffer);
42
43
void
JsonValueToBuffer(
const
formats::
json
::
Value
& value, std::string& buffer);
44
45
template
<
typename
JsonValue>
46
struct
JsonFormatter : BufferFormatterBase<JsonValue> {
47
using
BaseType = BufferFormatterBase<JsonValue>;
48
using
BaseType::BaseType;
49
50
template
<
typename
Buffer>
51
void
operator()(
const
UserTypes
&, Buffer& buffer)
const
{
52
if
constexpr
(!std::is_same_v<PlainJson, JsonValue>) {
53
buffer.push_back(kJsonbVersion);
54
}
55
56
detail::JsonValueToBuffer(
static_cast
<
const
formats::
json
::
Value
&>(
this
->value), buffer);
57
}
58
};
59
60
}
// namespace detail
61
62
namespace
traits
{
63
64
template
<>
65
struct
Input
<formats::
json
::
Value
> {
66
using
type =
io
::detail::JsonParser;
67
};
68
69
template
<>
70
struct
ParserBufferCategory<
io
::detail::JsonParser>
71
: std::integral_constant<
BufferCategory
,
BufferCategory
::
kPlainBuffer
> {};
72
73
template
<>
74
struct
Output
<formats::
json
::
Value
> {
75
using
type =
io
::detail::JsonFormatter<formats::
json
::
Value
>;
76
};
77
78
template
<>
79
struct
Output
<PlainJson> {
80
using
type =
io
::detail::JsonFormatter<PlainJson>;
81
};
82
83
}
// namespace traits
84
85
template
<>
86
struct
CppToSystemPg
<formats::
json
::
Value
> : PredefinedOid<
PredefinedOids
::kJsonb> {};
87
88
template
<>
89
struct
CppToSystemPg
<PlainJson> : PredefinedOid<
PredefinedOids
::kJson> {};
90
91
}
// namespace io
92
}
// namespace storages::postgres
93
94
USERVER_NAMESPACE_END
userver
storages
postgres
io
json_types.hpp
Generated on
for userver by
Doxygen
1.17.0