-
Notifications
You must be signed in to change notification settings - Fork 243
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
Iterating over map or array returned with MMDB_get_value() #255
Comments
To iterate over collection, you will need to use the See this example for maps: Lines 1255 to 1283 in ed7a425
And for arrays: Lines 1231 to 1239 in ed7a425
|
Thanks for the quick reply @oschwald. Is there a way to directly retrieve, without iteration, the value for a given key in a map, or the value for a given position in an array? Also, there seems to be no public API to do any of this; the code you pointed to depends on a couple of macros and static functions, which I would have to replicate in my code. Is this correct? If so, are there any plans to expose such APIs as part of the stable public interface of the library? I would love to have the equivalent of at least |
You can look up particular map values or array index values directly with
This would look up the value for the Similarly, the following would look up the first city:
|
Yes, this is how I am doing it today. But if I know before hand I will access several keys inside a map, I think it would be more efficient to first get the map entry, and then get the value for each key, instead of repeatedly searching for "names" / "en", "names" / "es", "names" / "de", etc. |
I see. I don't think we expose any functions to do this directly, although you likely could just create a new |
Ok, thanks for all the hints. I still think it would be nice to have an official API for this kind of access, but I understand if this is out of the scope for the library -- feel free to close the issue if this is not in the plans. |
I am working with the example data from the library's documentation:
Say I call
This will produce
entry_data.type == 7
, which is a MAP, as expected. How can I then retrieve the values for specific keys in this map? Becauseentry_data
is aMMDB_entry_data_s
and NOT aMMDB_entry_s
, I cannot pass it intoMMDB_get_value
.Same question would apply for an array:
This will produce with
entry_data.type == 11
, which is an ARRAY, as expected. How can I then retrieve the values for specific positions in this array?The text was updated successfully, but these errors were encountered: