userver
C++ Async Framework
Toggle main menu visibility
Documentation
API Groups
Namespaces
Reference
Class List
Class Index
File List
Macros
All
e
i
l
r
t
u
Functions
Macros
e
i
l
r
t
u
Examples
•
All
Classes
Namespaces
Files
Functions
Variables
Typedefs
Enumerations
Enumerator
Friends
Macros
Modules
Pages
Concepts
Loading...
Searching...
No Matches
json_helpers.hpp
Go to the documentation of this file.
1
#
pragma
once
2
3
/// @file userver/dump/json_helpers.hpp
4
/// @brief Convenience functions to load and dump as JSON in classes derived
5
/// from components::CachingComponentBase.
6
7
#
include
<
memory
>
8
#
include
<
string
>
9
#
include
<
string_view
>
10
11
#
include
<
userver
/
dump
/
common
.
hpp
>
12
#
include
<
userver
/
dump
/
operations
.
hpp
>
13
#
include
<
userver
/
dump
/
unsafe
.
hpp
>
14
#
include
<
userver
/
formats
/
json
/
serialize
.
hpp
>
15
#
include
<
userver
/
formats
/
json
/
string_builder
.
hpp
>
16
#
include
<
userver
/
formats
/
json
/
value
.
hpp
>
17
18
USERVER_NAMESPACE_BEGIN
19
20
namespace
dump
{
21
22
/// @brief Convenience function to use in
23
/// components::CachingComponentBase::WriteContents override to dump a type in
24
/// a human readable JSON format.
25
///
26
/// @see @ref scripts/docs/en/userver/cache_dumps.md
27
template
<
typename
T>
28
void
WriteJson
(
Writer
& writer,
const
T& contents) {
29
formats
::
json
::StringBuilder sb;
30
WriteToStream(contents, sb);
31
WriteStringViewUnsafe
(
writer
,
sb
.
GetString
(
)
)
;
32
WriteStringViewUnsafe
(
writer
,
"\n"
)
;
33
}
28
void
WriteJson
(
Writer
& writer,
const
T& contents) {
…
}
34
35
/// @brief Convenience function to use in
36
/// components::CachingComponentBase::ReadContents override to load a dump in
37
/// a human readable JSON format.
38
///
39
/// @see @ref scripts/docs/en/userver/cache_dumps.md
40
template
<
typename
T>
41
std::unique_ptr<
const
T>
ReadJson
(
Reader
& reader) {
42
return
std::make_unique<
const
T>(
formats
::
json
::
FromString
(
ReadEntire
(
reader
)
)
.As<T>());
43
}
41
std::unique_ptr<
const
T>
ReadJson
(
Reader
& reader) {
…
}
44
45
}
// namespace dump
46
47
USERVER_NAMESPACE_END
userver
dump
json_helpers.hpp
Generated on Wed Apr 30 2025 15:52:41 for userver by
Doxygen
1.13.2