When the raw type may not match the required encoded size, this helper makes
intent clear and avoids a common verbose pattern:
intX_t t = val;
encode(t, bl);
and
intX_t t;
decode(t, p);
val = t;
Signed-off-by: Patrick Donnelly <pdonnell@ibm.com>
#include <string>
#include <string_view>
#include <tuple>
+#include <type_traits>
#include <optional>
#include <unordered_map>
#include <unordered_set>
ENCODE_DUMP_PRE(); c.encode(bl, features); ENCODE_DUMP_POST(cl); } \
inline void decode(cl &c, ::ceph::bufferlist::const_iterator &p) { c.decode(p); }
+template<typename Int>
+inline void encode_assign(const auto& t, ::ceph::bufferlist& bl, uint64_t features=0)
+{
+ Int i = static_cast<Int>(t);
+ ::encode(i, bl);
+}
+
+template<typename Int>
+inline void decode_assign(auto& t, ::ceph::bufferlist::const_iterator& p)
+{
+ Int i;
+ ::decode(i, p);
+ t = static_cast<std::remove_reference_t<decltype(t)>>(i);
+}
// string
inline void encode(std::string_view s, bufferlist& bl, uint64_t features=0)