diff options
author | William A. Kennington III <wak@google.com> | 2019-04-24 14:44:26 -0700 |
---|---|---|
committer | William A. Kennington III <wak@google.com> | 2019-04-29 12:06:35 -0700 |
commit | e2aec26caacdc65711a96ce3b6dbaa5ea526fc1f (patch) | |
tree | b858890a099c0b52f48eb222c5b7c80367cfa9dd /include/ipmid | |
parent | 906e0f802b56d26e7e0c65eba797fa8a596dee91 (diff) | |
download | phosphor-host-ipmid-e2aec26caacdc65711a96ce3b6dbaa5ea526fc1f.tar.gz phosphor-host-ipmid-e2aec26caacdc65711a96ce3b6dbaa5ea526fc1f.zip |
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>
Diffstat (limited to 'include/ipmid')
-rw-r--r-- | include/ipmid/message/pack.hpp | 17 |
1 files changed, 17 insertions, 0 deletions
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 @@ struct PackSingle<std::vector<uint8_t>> } }; +/** @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...>> |