userver: userver/formats/yaml/serialize.hpp Source File
Loading...
Searching...
No Matches
serialize.hpp
Go to the documentation of this file.
1#pragma once
2
3/// @file userver/formats/yaml/serialize.hpp
4/// @brief Parsers and serializers to/from string and stream
5
6#include <iosfwd>
7
8#include <userver/formats/json_fwd.hpp>
9#include <userver/formats/yaml/value.hpp>
10
11USERVER_NAMESPACE_BEGIN
12
13namespace formats::parse {
14
15/// @brief Converts a YAML value to JSON format
16///
17/// @throws formats::yaml::Exception if the YAML value is missing or contains
18/// an unknown node type that cannot be converted to JSON
19formats::json::Value Parse(const formats::yaml::Value& yaml, formats::parse::To<formats::json::Value>);
20
21/// @brief Converts a JSON value to YAML format
22///
23/// @throws formats::json::Exception if the JSON value is missing or contains
24/// an unknown node type that cannot be converted to YAML
25formats::yaml::Value Parse(const formats::json::Value& json, formats::parse::To<formats::yaml::Value>);
26
27} // namespace formats::parse
28
29namespace formats::yaml {
30
31/// Parse YAML from string
32formats::yaml::Value FromString(const std::string& doc);
33
34/// Parse YAML from stream
35formats::yaml::Value FromStream(std::istream& is);
36
37/// Serialize YAML to stream
38void Serialize(const formats::yaml::Value& doc, std::ostream& os);
39
40/// Serialize YAML to string
41std::string ToString(const formats::yaml::Value& doc);
42
43/// Blocking operations that should not be used on main task processor after
44/// startup
45namespace blocking {
46/// @brief Read YAML from file
47/// @see formats::yaml::FromFile
48formats::yaml::Value FromFile(const std::string& path);
49} // namespace blocking
50
51namespace impl {
52formats::yaml::Value FromStringAllowRepeatedKeys(const std::string& doc);
53} // namespace impl
54
55} // namespace formats::yaml
56
57USERVER_NAMESPACE_END