'How to lookup element by key using flatbuffer's Object API

Is it possible to lookup elements by key with the object API just like it's possible in the non-object API with the "LookUpByKey" method?

I can't find any method that seems to do that.

Am I supposed to implement a binary search by myself on the vector?

Is the vector assumed to be already sorted?



Solution 1:[1]

I think you need to use mini-reflection or full reflection for this task.

You can read more about reflection in the docs or see an example where it's used in their testing code.

Here's a nice tutorial by jorenjoestar from someone using reflection that I found helpful myself.

Also the vectors are not assumed to be sorted but you can pre-sort a vector and set the flatbuffer contents to that sorted vector.

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1 Steven