PEL: Add Stream ops for std::vector<char>
Add << and >> operators to the Stream class for use with a
std::vector<char>.
Signed-off-by: Matt Spinler <spinler@us.ibm.com>
Change-Id: I22a08bb6518f9aed2385bcdce446a67ea9ea386d
diff --git a/extensions/openpower-pels/stream.hpp b/extensions/openpower-pels/stream.hpp
index 5c813b2..4922bc7 100644
--- a/extensions/openpower-pels/stream.hpp
+++ b/extensions/openpower-pels/stream.hpp
@@ -160,6 +160,23 @@
}
/**
+ * @brief Extraction operator for a std::vector<char>
+ *
+ * The vector's size is the amount extracted.
+ *
+ * @param[out] value - filled in with the value
+ * @return Stream&
+ */
+ Stream& operator>>(std::vector<char>& value)
+ {
+ if (!value.empty())
+ {
+ read(value.data(), value.size());
+ }
+ return *this;
+ }
+
+ /**
* @brief Insert operator for a uint8_t
*
* @param[in] value - the value to write to the stream
@@ -240,6 +257,23 @@
}
/**
+ * @brief Insert operator for a std::vector<char>
+ *
+ * The full vector is written to the stream.
+ *
+ * @param[in] value - the value to write to the stream
+ * @return Stream&
+ */
+ Stream& operator<<(const std::vector<char>& value)
+ {
+ if (!value.empty())
+ {
+ write(value.data(), value.size());
+ }
+ return *this;
+ }
+
+ /**
* @brief Sets the offset of the stream
*
* @param[in] newOffset - the new offset