message/pack: Support packing string_views

Now we don't need to make an intermediate copy of our data into an array
before packing it into a payload.

Change-Id: Iac79a79e0ae95835cb67d617a966a92ce8dcd5f8
Signed-off-by: William A. Kennington III <wak@google.com>
diff --git a/include/ipmid/message/pack.hpp b/include/ipmid/message/pack.hpp
index deb0a5a..388bf2f 100644
--- a/include/ipmid/message/pack.hpp
+++ b/include/ipmid/message/pack.hpp
@@ -20,6 +20,7 @@
 #include <memory>
 #include <optional>
 #include <phosphor-logging/log.hpp>
+#include <string_view>
 #include <tuple>
 #include <utility>
 #include <variant>
@@ -249,6 +250,22 @@
     }
 };
 
+/** @brief Specialization of PackSingle for std::string_view */
+template <>
+struct PackSingle<std::string_view>
+{
+    static int op(Payload& p, const std::string_view& t)
+    {
+        if (p.bitCount != 0)
+        {
+            return 1;
+        }
+        p.raw.reserve(p.raw.size() + t.size());
+        p.raw.insert(p.raw.end(), t.begin(), t.end());
+        return 0;
+    }
+};
+
 /** @brief Specialization of PackSingle for std::variant<T, N> */
 template <typename... T>
 struct PackSingle<std::variant<T...>>