YAML Emitter multiline lines

44 views Asked by At

How do i write multiline yaml file, that looks like this: yaml_hex_dump

I am using c++ library yaml-cpp. Here is a peek to my code: YAML::Emitter out; out << YAML::BeginMap; out << YAML::Key << "name" << YAML::Value << "PKS2023/24" << YAML::Key << "pcap_name" << YAML::Value << "abcd.pcap"; out << YAML::Key << "packets" << YAML::Value;

I tried new mapping iside the hexa_frame value. But it started a new line and loosed the | pipe.

1

There are 1 answers

0
Botje On

The value for hexa_frame is just a long string with embedded newlines. You can convince yaml-cpp to generate it using YAML::Literal:

const char dubious_hex_string[] =
R"(23 0a 23 20 4e 65 74 77 6f 72 6b 20 73 65 72 76
69 63 65 73 2c 20 49 6e 74 65 72 6e 65 74 20 73
74 79 6c 65 0a 23 0a 23 20 4e 6f 74 65 20 74 68
61 74 20 69 74 20 69 73 20 70 72 65 73 65 6e 74
6c 79 20 74 68 65 20 70 6f 6c 69 63 79 20 6f 66
20 49 41 4e 41 20 74 6f 20 61 73 73 69 67 6e 20)";

YAML::Emitter out;
out << YAML::BeginMap;
out << YAML::Key << "hexa_frame";
out << YAML::Value << YAML::Literal << dubious_hex_string;
out << YAML::EndMap;