-
Using the following yaml in file "test.yaml": commands:
IAU_BOOT_RST:
- dmoab_scid: {value: 1, type: uint8_t, size: 4}
- dmoab_opcode: {value: 2, type: uint8_t, size: 4}
- dmoab_extension: {value: 3, type: uint8_t, size: 8}
- dmoab_operand: {value: [0,0,0,0,17], type: vector<uint8_t>, size: 40}
- dmoab_crc: {value: 0, type: uint8_t, size: 8}
IAU_WD_EN:
- dmoab_scid: {value: 4, type: uint8_t, size: 4}
- dmoab_opcode: {value: 5, type: uint8_t, size: 4}
- dmoab_extension: {value: 6, type: uint8_t, size: 8}
- dmoab_operand: {value: [0,0,0,0,34], type: vector<uint8_t>, size: 40}
- dmoab_crc: {value: 0, type: uint8_t, size: 8} I want to access the integer value of dmoab_extension, size for each command. std::string contents = file_get_contents<std::string>("test.yaml");
ryml::Tree tree = ryml::parse_in_arena(ryml::to_csubstr(contents));
ryml::NodeRef root = tree["commands"];
// iterate children
for (ryml::NodeRef const& command : root.children())
{
std::cout << "size " << command["IAU_BOOT_RST"]["dmoab_extension"]["size"].val() << std::endl
} Of course this code crashes. |
Beta Was this translation helpful? Give feedback.
Replies: 1 comment 4 replies
-
Your loop variable is already the command, so you are looking twice for What you want is simply this: for (ryml::NodeRef const& cmd : tree["commands"].children())
std::cout << cmd.key() << ": size=" << cmd["dmoab_extension"]["size"].val() << "\n"; As for the conversion, it's in the quickstart. In this case: int size;
cmd["dmoab_extension"]["size"] >> size; |
Beta Was this translation helpful? Give feedback.
Your loop variable is already the command, so you are looking twice for
IAU_BOOT_RST
. That is, you are doing the equivalent totree["commands"]["IAU_BOOT_RST"]["IAU_BOOT_RST"]["dmoab_extension"]["size"]
, and it fails.What you want is simply this:
As for the conversion, it's in the quickstart. In this case: