From 54bc44c056dba39bc0f753fb8603e77fc3917179 Mon Sep 17 00:00:00 2001 From: "Adam C. Emerson" Date: Tue, 9 Jan 2018 23:27:51 -0500 Subject: [PATCH] encoding: Encode/decode of arbitrary tuples Using ceph::for_each to avoid fiddling with indices everywhere. Signed-off-by: Adam C. Emerson --- src/include/encoding.h | 24 ++++++++++++++++++++---- 1 file changed, 20 insertions(+), 4 deletions(-) diff --git a/src/include/encoding.h b/src/include/encoding.h index 8b9c3f40f92af..943b42c8a1b3c 100644 --- a/src/include/encoding.h +++ b/src/include/encoding.h @@ -19,6 +19,7 @@ #include #include #include +#include #include #include @@ -30,6 +31,8 @@ #include "include/memory.h" +#include "common/convenience.h" + #include "byteorder.h" #include "buffer.h" @@ -492,9 +495,6 @@ inline void decode(T &o, bufferlist& bl) assert(p.end()); } - - - // boost optional template inline void encode(const boost::optional &p, bufferlist &bl) @@ -523,7 +523,23 @@ inline void decode(boost::optional &p, bufferlist::iterator &bp) #pragma GCC diagnostic pop #pragma GCC diagnostic warning "-Wpragmas" -//triple tuple +// std::tuple +template +inline void encode(const std::tuple &t, bufferlist& bl) +{ + ceph::for_each(t, [&bl](const auto& e) { + encode(e, bl); + }); +} +template +inline void decode(std::tuple &t, bufferlist::iterator &bp) +{ + ceph::for_each(t, [&bp](auto& e) { + decode(e, bp); + }); +} + +//triple boost::tuple template inline void encode(const boost::tuple &t, bufferlist& bl) { -- 2.39.5