summaryrefslogtreecommitdiff
path: root/scripts
diff options
context:
space:
mode:
authorEd Tanous <edtanous@google.com>2022-02-07 20:37:21 +0300
committerEd Tanous <edtanous@google.com>2022-02-28 03:17:20 +0300
commit30a3c431478584109d6d3a52f4d9541d5275902a (patch)
tree06068ea65118d3e86cbe0371b8b78f74a672f22a /scripts
parent4a750f43775f123289d139b637f7893d517baeb3 (diff)
downloadbmcweb-30a3c431478584109d6d3a52f4d9541d5275902a.tar.xz
Generate indexes for message registries
Being able to index into the message registry constexpr arrays will be useful in the future, so update the parse_registries script to generate an Index enum class, that allows directly indexing into the constexpr table when necessary. These indexes are used in the patchset here: https://gerrit.openbmc-project.xyz/c/openbmc/bmcweb/+/50950 to avoid a binary search lookup for each entry. Tested: No-op change, code inspection only. Signed-off-by: Ed Tanous <edtanous@google.com> Change-Id: I345cc26a2b17b5bcd8cfb0055642f4ae443caad4
Diffstat (limited to 'scripts')
-rwxr-xr-xscripts/parse_registries.py16
1 files changed, 14 insertions, 2 deletions
diff --git a/scripts/parse_registries.py b/scripts/parse_registries.py
index d64e540de2..8334eaefd9 100755
--- a/scripts/parse_registries.py
+++ b/scripts/parse_registries.py
@@ -91,7 +91,9 @@ for file, json_dict, namespace, url in files:
registry.write(
"constexpr std::array<MessageEntry, {}> registry = {{".format(
len(json_dict["Messages"])))
- for messageId, message in sorted(json_dict["Messages"].items()):
+
+ messages_sorted = sorted(json_dict["Messages"].items())
+ for messageId, message in messages_sorted:
registry.write("MessageEntry{")
registry.write("\"{}\",".format(messageId))
registry.write("{")
@@ -108,7 +110,17 @@ for file, json_dict, namespace, url in files:
registry.write("},")
registry.write("\"{}\",".format(message["Resolution"]))
registry.write("}},")
- registry.write("};}\n")
+
+ registry.write("\n};")
+
+ registry.write("\n\nenum class Index {\n")
+ for index, (messageId, message) in enumerate(messages_sorted):
+ messageId = messageId[0].lower() + messageId[1:]
+ registry.write(
+ "{} = {},\n".format(messageId, index))
+ registry.write("};")
+ registry.write("}")
+
clang_format(file)