How-to emits and parses raw binary data using yaml-cpp

Is it possible to emit and read (analyze) binary data (image, file, etc.)? As shown here: http://yaml.org/type/binary.html How can I do this in yaml-cpp?

+3
source share
2 answers

Like version 425 , yes! (for emission)

YAML::Emitter emitter;
emitter << YAML::Binary("Hello, World!", 13);
std::cout << emitter.c_str();

exits

--- !!binary "SGVsbG8sIFdvcmxkIQ=="

Syntax

YAML::Binary(const char *bytes, std::size_t size);

I was not sure how to pass an array of bytes: charnot necessarily one byte, so I'm not sure how portable the algorithm is. What format is your byte array, usually in?

( , uint8_t ++, .)

, yaml-cpp , .

+2

, / yaml yaml-cpp.

, YAML:: Node node yaml, yaml-cpp: https://github.com/jbeder/yaml-cpp/wiki/Tutorial).

yaml node:

YAML:: = node.as();

const unsigned char * data = binary.data();

std:: size_t size = binary.size();

"" "".

+1

Source: https://habr.com/ru/post/1771995/


All Articles