Skip to content

Defined in header <fkYAML/node.hpp>

fkyaml::basic_node::serialize_docs

static std::string serialize_docs(const std::vector<basic_node>& docs);

Serializes YAML documents into a string.
This function serializes the given docs parameter with the separation line (...) between YAML documents.
Regarding the serialization of each document, see the documentation for the serialize() function which this function calls internally.
Just as the serialize() function does, fkYAML unconditionally uses LFs as the line break format in serialization outputs, and there is currently no way to change it to use CR+LFs instead.

<YAML Document 1>
...
<YAML Document 2>
# the last document end marker (...) is omitted since it's redundant.

Parameters

docs [in]
basic_node objects to be serialized.

Return Value

The resulting string object from the serialization of the docs object.

Example
#include <iostream>
#include <fkYAML/node.hpp>

int main() {
    // create a basic_node object.
    fkyaml::node n1 = {
        {"foo", true},
        {"bar", {1, 2, 3}},
        {"baz", {{"qux", 3.14}, {"corge", nullptr}}},
        {{{true, 123}}, false},
        {{1.23, 4.56, 7.89}, 123456789}};
    // set tags to some nodes.
    n1["foo"].add_tag_name("!!bool");
    n1["bar"][1].add_tag_name("!<tag:yaml.org,2002:int>");
    // set an anchor name to a node.
    n1["baz"].add_anchor_name("anchor");

    // create another one.
    fkyaml::node n2 = {"foo", 123, true};

    // serialize the basic_node objects into a string.
    std::cout << fkyaml::node::serialize_docs({n1, n2}) << std::endl;

    return 0;
}

output:

? - 1.23
  - 4.56
  - 7.89
: 123456789
? true: 123
: false
bar:
  - 1
  - !<tag:yaml.org,2002:int> 2
  - 3
baz: &anchor
  corge: null
  qux: 3.14
foo: !!bool true
...
- foo
- 123
- true

See Also