diff options
author | Vernon Mauery <vernon.mauery@linux.intel.com> | 2019-04-08 10:01:33 -0700 |
---|---|---|
committer | Vernon Mauery <vernon.mauery@linux.intel.com> | 2019-04-09 17:42:38 +0000 |
commit | 508c457688e4be878f75f7951ac2e5e95e7de3a8 (patch) | |
tree | 28c79d0cbdebeb7e850cea7ae4a5ddd80505a784 /include | |
parent | 336405b85e88fdc46896437cb02fe52b46079369 (diff) | |
download | phosphor-host-ipmid-508c457688e4be878f75f7951ac2e5e95e7de3a8.tar.gz phosphor-host-ipmid-508c457688e4be878f75f7951ac2e5e95e7de3a8.zip |
Add a tuple type for packing
At the top level, payload had the ability to pack a tuple, but it did it
by splitting it into its parts and packing those individually. But if
one of those parts was a tuple, it would fail. This moves the tuple
packing code into the packing templates so that it is possible to pack a
nested tuple of tuples.
Tested-by: newly written tuple unit tests pass
Change-Id: Icd80926314072df78b0083a823dcfb46e944e365
Signed-off-by: Vernon Mauery <vernon.mauery@linux.intel.com>
Diffstat (limited to 'include')
-rw-r--r-- | include/ipmid/message.hpp | 18 | ||||
-rw-r--r-- | include/ipmid/message/pack.hpp | 11 |
2 files changed, 11 insertions, 18 deletions
diff --git a/include/ipmid/message.hpp b/include/ipmid/message.hpp index 4079eab..030618f 100644 --- a/include/ipmid/message.hpp +++ b/include/ipmid/message.hpp @@ -252,24 +252,6 @@ struct Payload return packRet; } - /** - * @brief pack a tuple of values (of any supported type) into the buffer - * - * This will pack the elements of the tuple as if each one was passed in - * individually, as if passed into the above variadic function. - * - * @tparam Types - the implicitly declared list of the tuple element types - * - * @param t - the tuple of values to pack - * - * @return int - non-zero on pack errors - */ - template <typename... Types> - int pack(std::tuple<Types...>& t) - { - return std::apply([this](Types&... args) { return pack(args...); }, t); - } - /****************************************************************** * Request operations *****************************************************************/ diff --git a/include/ipmid/message/pack.hpp b/include/ipmid/message/pack.hpp index 8a9abe1..4314ac1 100644 --- a/include/ipmid/message/pack.hpp +++ b/include/ipmid/message/pack.hpp @@ -93,6 +93,17 @@ struct PackSingle } }; +/** @brief Specialization of PackSingle for std::tuple<T> */ +template <typename... T> +struct PackSingle<std::tuple<T...>> +{ + static int op(Payload& p, const std::tuple<T...>& v) + { + return std::apply([&p](const T&... args) { return p.pack(args...); }, + v); + } +}; + /** @brief Specialization of PackSingle for std::string * represented as a UCSD-Pascal style string */ |