userver
C++ Async Framework
Toggle main menu visibility
Loading...
Searching...
No Matches
serialize.hpp
Go to the documentation of this file.
1
#pragma once
2
5
6
#include <iosfwd>
7
#include <string>
8
#include <string_view>
9
10
#include <fmt/format.h>
11
12
#include <
userver/formats/json/value.hpp
>
13
#include <
userver/utils/fast_pimpl.hpp
>
14
#include <
userver/utils/fmt_compat.hpp
>
15
16
USERVER_NAMESPACE_BEGIN
17
18
namespace
logging
{
19
20
class
LogHelper
;
21
22
}
// namespace logging
23
24
namespace
formats::json
{
25
26
constexpr
inline
std::size_t kDepthParseLimit = 128;
27
29
formats::json::Value
FromString
(std::string_view doc);
30
32
formats::json::Value
FromStream
(std::istream& is);
33
35
void
Serialize(
const
formats::json::Value
& doc, std::ostream& os);
36
38
std::string
ToString
(
const
formats::json::Value
& doc);
39
42
std::string
ToStableString
(
const
formats::json::Value
& doc);
43
45
std::string
ToStableString
(
formats::json::Value
&& doc);
46
50
std::string
ToPythonCompatibleStableString
(
const
formats::json::Value
& doc);
51
53
std::string
ToPythonCompatibleStableString
(
formats::json::Value
&& doc);
54
56
struct
PrettyFormat
final {
57
char
indent_char{
' '
};
58
std::size_t indent_char_count{2};
59
};
60
62
std::string
ToPrettyString
(
const
formats::json::Value
& doc,
PrettyFormat
format = {});
63
65
logging::LogHelper
&
operator<<
(
logging::LogHelper
&,
const
formats::json::Value
&);
66
68
namespace
blocking
{
70
formats::json::Value
FromFile
(
const
std::string& path);
71
}
// namespace blocking
72
73
namespace
impl {
74
75
class
StringBuffer final {
76
public
:
77
explicit
StringBuffer(
const
formats::json::Value
& value);
78
~StringBuffer();
79
80
std::string_view GetStringView()
const
;
81
82
private
:
83
struct
Impl;
84
static
constexpr
std::size_t kSize = 48;
85
static
constexpr
std::size_t kAlignment = 8;
86
utils::FastPimpl<Impl, kSize, kAlignment>
pimpl_;
87
};
88
89
}
// namespace impl
90
91
}
// namespace formats::json
92
93
USERVER_NAMESPACE_END
94
95
template
<>
96
struct
fmt::formatter<USERVER_NAMESPACE::
formats::json::Value
> : fmt::formatter<std::string_view> {
97
constexpr
static
auto
parse(format_parse_context& ctx) ->
decltype
(ctx.begin()) {
return
ctx.begin(); }
98
99
template
<
typename
FormatContext>
100
auto
format(
const
USERVER_NAMESPACE::formats::json::Value& value, FormatContext& ctx)
101
USERVER_FMT_CONST ->
decltype
(ctx.out()) {
102
const
USERVER_NAMESPACE::formats::json::impl::StringBuffer buffer(value);
103
return
fmt::format_to(ctx.out(),
"{}"
, buffer.GetStringView());
104
}
105
};
userver
formats
json
serialize.hpp
Generated on
for userver by
Doxygen
1.17.0