regulators: Support a string or vector for VPD
Add a 'byte_values' alternative to the 'value' entry in the compare VPD
action. This is to support VPD values that are not strings, such as
'HW', a new IBM keyword that describes the version of a piece of
hardware.
To support this, the VPD class now treats all VPD keyword values as
vectors of uint8_ts, including in its data cache. If a compare VPD
action in the JSON contains a string value, it will be converted to the
vector before the CompareVPDAction class is created.
Signed-off-by: Matt Spinler <spinler@us.ibm.com>
Change-Id: I3fcabf896f4885feae1b07ee2c3da5929cf8bfa4
diff --git a/phosphor-regulators/src/config_file_parser.cpp b/phosphor-regulators/src/config_file_parser.cpp
index 5238741..0b4673d 100644
--- a/phosphor-regulators/src/config_file_parser.cpp
+++ b/phosphor-regulators/src/config_file_parser.cpp
@@ -274,10 +274,26 @@
std::string keyword = parseString(keywordElement);
++propertyCount;
- // Required value property
- const json& valueElement = getRequiredProperty(element, "value");
- std::string value = parseString(valueElement);
- ++propertyCount;
+ // Either value or byte_values required property
+ auto valueIt = element.find("value");
+ std::vector<uint8_t> value{};
+ auto byteValuesIt = element.find("byte_values");
+ if ((valueIt != element.end()) && (byteValuesIt == element.end()))
+ {
+ std::string stringValue = parseString(*valueIt);
+ value.insert(value.begin(), stringValue.begin(), stringValue.end());
+ ++propertyCount;
+ }
+ else if ((valueIt == element.end()) && (byteValuesIt != element.end()))
+ {
+ value = parseHexByteArray(*byteValuesIt);
+ ++propertyCount;
+ }
+ else
+ {
+ throw std::invalid_argument{
+ "Invalid property: Must contain either value or byte_values"};
+ }
// Verify no invalid properties exist
verifyPropertyCount(element, propertyCount);