mirror of
https://github.com/espressif/openthread.git
synced 2026-09-01 06:49:54 +00:00
[common] add BinarySearch module and Stringfy (#7294)
This commit adds set of generic binary search related functions in OpenThread core under `BinarySearch` module. The binary search module replaces and enhances the existing `Lookup` table module (which was limited to search based on strings and mainly used by CLI to map from command string to a handler function). This commit also adds a new class `Stringfy` in `string.hpp` to help convert from a set of `uint16_t` values (e.g., a non-sequential `enum`) to strings using binary search in a table. The new methods are used for converting `Coap::Code` and `IpProto` enumerations to corresponding strings.
This commit is contained in:
+1
-1
@@ -277,7 +277,7 @@ otError UdpExample::Process(Arg aArgs[])
|
||||
ExitNow();
|
||||
}
|
||||
|
||||
command = Utils::LookupTable::Find(aArgs[0].GetCString(), sCommands);
|
||||
command = BinarySearch::Find(aArgs[0].GetCString(), sCommands);
|
||||
VerifyOrExit(command != nullptr, error = OT_ERROR_INVALID_COMMAND);
|
||||
|
||||
error = (this->*command->mHandler)(aArgs + 1);
|
||||
|
||||
Reference in New Issue
Block a user