bios: enum: Remove sorting of possible values
Possible values are sorted in byte order at runtime,
which will cause inconsistencies with the order in JSON file.
eg
json:
possible_values: ["On", "Off"];
runtime vector:
possible_values: ["Off", "On"];
pldm uses the index of the possible values to set the
enum attribute, it's better to not sort it.
Tested:
tested on fp5280g2, with enum_attrs.json
https://gist.github.com/wangzqbj/b24558331cb35d14fca3b555ef03e458
possible_values: [ "On", "Off" ];
default_value: [ "Off" ]
Before the commit:
GetAttributeCurrentValueByHandle:
root@fp5280g2:/tmp# pldmtool raw --data 0x80 0x03 0x08 0x00 0x00 0x00 0x00 0x00 0x01 0x00
...
...
Response Message:
08 01 00 03 08 00 00 00 00 00 05 01 00 //current value index = 0
After:
GetAttributeCurrentValueByHandle:
root@fp5280g2:/tmp# pldmtool raw --data 0x80 0x03 0x08 0x00 0x00 0x00 0x00 0x00 0x01 0x00
...
...
Response Message:
08 01 00 03 08 00 00 00 00 00 05 01 01 //current value index = 1
Signed-off-by: John Wang <wangzqbj@inspur.com>
Change-Id: I383fdfcdfdfc79099d5d43919f22c5b4676bcc71
diff --git a/libpldmresponder/bios.cpp b/libpldmresponder/bios.cpp
index fe20140..61b5e49 100644
--- a/libpldmresponder/bios.cpp
+++ b/libpldmresponder/bios.cpp
@@ -419,7 +419,8 @@
std::vector<uint8_t> defHdls;
for (const auto& defs : defVals)
{
- auto index = std::lower_bound(possiVals.begin(), possiVals.end(), defs);
+ auto index = std::find_if(possiVals.begin(), possiVals.end(),
+ [&defs](const auto& v) { return defs == v; });
if (index != possiVals.end())
{
defHdls.push_back(index - possiVals.begin());
@@ -454,12 +455,8 @@
continue;
}
bool readOnly = (std::get<0>(value));
- PossibleValues possiVals = std::get<1>(value);
- DefaultValues defVals = std::get<2>(value);
- // both the possible and default values are stored in sorted manner to
- // ease in fetching back/comparison
- std::sort(possiVals.begin(), possiVals.end());
- std::sort(defVals.begin(), defVals.end());
+ const PossibleValues& possiVals = std::get<1>(value);
+ const DefaultValues& defVals = std::get<2>(value);
std::vector<StringHandle> possiValsByHdl;
for (const auto& elem : possiVals)