Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

How to get keys of map? #8

Open
d9k opened this issue Nov 24, 2024 · 2 comments
Open

How to get keys of map? #8

d9k opened this issue Nov 24, 2024 · 2 comments

Comments

@d9k
Copy link

d9k commented Nov 24, 2024

We can query key if we know it:

Cborg intent = top.find("body").find("intents")

But how to get all keys of the map?

@d9k
Copy link
Author

d9k commented Nov 24, 2024

Or better make iterator which returns key and value

@d9k
Copy link
Author

d9k commented Nov 24, 2024

Seems to be fixed at TRUEPIC/cborg:

See test9() at cborg/test/test.cpp at master · TRUEPIC/cborg:

Cborg top(buffer, sizeof(buffer));

printf("Test 9: Iterate map.\r\n");

Cborg key = top.getKey(0);
std::string keyName;
key.getString(keyName);
Cborg val = top.find(keyName.c_str(), keyName.size());
uint32_t value;
val.getUnsigned(&value);
printf("First key: %s value: %d\r\n", keyName.c_str(), value);

key = top.getKey(1);
key.getString(keyName);
val = top.find(keyName.c_str(), keyName.size());
val.getUnsigned(&value);
printf("Second key: %s value: %d\r\n", keyName.c_str(), value);

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant