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/// @brief Converts a YAML value to JSON string format
28///
29/// @throws formats::yaml::Exception if the YAML value is missing or contains
30/// an unknown node type that cannot be converted to JSON
31formats::json::RawString Parse(const formats::yaml::Value& value, formats::parse::To<formats::json::RawString>);
32
33} // namespace formats::parse
34
35namespace formats::yaml {
36
37/// Parse YAML from string
38formats::yaml::Value FromString(const std::string& doc);
39
40/// Parse YAML from stream
41formats::yaml::Value FromStream(std::istream& is);
42
43/// Serialize YAML to stream
44void Serialize(const formats::yaml::Value& doc, std::ostream& os);
45
46/// Serialize YAML to string
47std::string ToString(const formats::yaml::Value& doc);
48
49/// @brief Blocking operations that should not be used on main task processor after startup
50namespace blocking {
51/// @brief Read YAML from file
52/// @see formats::yaml::FromFile
53formats::yaml::Value FromFile(const std::string& path);
54} // namespace blocking
55
56namespace impl {
57formats::yaml::Value FromStringAllowRepeatedKeys(const std::string& doc);
58} // namespace impl
59
60} // namespace formats::yaml
61
62USERVER_NAMESPACE_END