regulators: Implements support for i2c_write_bytes

Implements support for parsing the i2c_write_bytes JSON elements in the
configuration file parser.

Signed-off-by: Bob King <Bob_King@wistron.com>
Change-Id: I6233361a6cc5a243b563e59e1aec70eec7a5b7f5
diff --git a/phosphor-regulators/src/config_file_parser.hpp b/phosphor-regulators/src/config_file_parser.hpp
index abfa4f5..a8286f1 100644
--- a/phosphor-regulators/src/config_file_parser.hpp
+++ b/phosphor-regulators/src/config_file_parser.hpp
@@ -19,6 +19,7 @@
 #include "chassis.hpp"
 #include "i2c_write_bit_action.hpp"
 #include "i2c_write_byte_action.hpp"
+#include "i2c_write_bytes_action.hpp"
 #include "pmbus_write_vout_command_action.hpp"
 #include "rule.hpp"
 
@@ -203,6 +204,53 @@
 }
 
 /**
+ * Parses a JSON element containing a byte value expressed as a hexadecimal
+ * string.
+ *
+ * The JSON number data type does not support the hexadecimal format.  For this
+ * reason, hexadecimal byte values are stored as strings in the configuration
+ * file.
+ *
+ * Returns the corresponding C++ uint8_t value.
+ *
+ * Throws an exception if parsing fails.
+ *
+ * @param element JSON element
+ * @return uint8_t value
+ */
+inline uint8_t parseHexByte(const nlohmann::json& element)
+{
+    if (!element.is_string())
+    {
+        throw std::invalid_argument{"Element is not a string"};
+    }
+    std::string value = element;
+
+    bool isHex = (value.compare(0, 2, "0x") == 0) && (value.size() > 2) &&
+                 (value.size() < 5) &&
+                 (value.find_first_not_of("0123456789abcdefABCDEF", 2) ==
+                  std::string::npos);
+    if (!isHex)
+    {
+        throw std::invalid_argument{"Element is not hexadecimal string"};
+    }
+    return static_cast<uint8_t>(std::stoul(value, 0, 0));
+}
+
+/**
+ * Parses a JSON element containing an array of byte values expressed as a
+ * hexadecimal strings.
+ *
+ * Returns the corresponding C++ uint8_t values.
+ *
+ * Throws an exception if parsing fails.
+ *
+ * @param element JSON element
+ * @return vector of uint8_t
+ */
+std::vector<uint8_t> parseHexByteArray(const nlohmann::json& element);
+
+/**
  * Parses a JSON element containing an i2c_write_bit action.
  *
  * Returns the corresponding C++ I2CWriteBitAction object.
@@ -229,6 +277,19 @@
     parseI2CWriteByte(const nlohmann::json& element);
 
 /**
+ * Parses a JSON element containing an i2c_write_bytes action.
+ *
+ * Returns the corresponding C++ I2CWriteBytesAction object.
+ *
+ * Throws an exception if parsing fails.
+ *
+ * @param element JSON element
+ * @return I2CWriteBytesAction object
+ */
+std::unique_ptr<I2CWriteBytesAction>
+    parseI2CWriteBytes(const nlohmann::json& element);
+
+/**
  * Parses a JSON element containing an 8-bit signed integer.
  *
  * Returns the corresponding C++ int8_t value.
@@ -332,31 +393,6 @@
 }
 
 /**
- * Parses a JSON element containing a hexadecimal string.
- *
- * Returns the corresponding C++ uint8_t value.
- *
- * Throws an exception if parsing fails.
- *
- * @param element JSON element
- * @return uint8_t value
- */
-inline uint8_t parseStringToUint8(const nlohmann::json& element)
-{
-    std::string value = parseString(element);
-
-    bool isHex = (value.compare(0, 2, "0x") == 0) && (value.size() > 2) &&
-                 (value.size() < 5) &&
-                 (value.find_first_not_of("0123456789abcdefABCDEF", 2) ==
-                  std::string::npos);
-    if (!isHex)
-    {
-        throw std::invalid_argument{"Element is not hexadecimal string"};
-    }
-    return static_cast<uint8_t>(std::stoul(value, 0, 0));
-}
-
-/**
  * Parses a JSON element containing an 8-bit unsigned integer.
  *
  * Returns the corresponding C++ uint8_t value.