]> git.apps.os.sepia.ceph.com Git - ceph.git/commitdiff
encoding: Encode/decode of arbitrary tuples
authorAdam C. Emerson <aemerson@redhat.com>
Wed, 10 Jan 2018 04:27:51 +0000 (23:27 -0500)
committerAdam C. Emerson <aemerson@redhat.com>
Fri, 12 Jan 2018 05:51:04 +0000 (00:51 -0500)
Using ceph::for_each to avoid fiddling with indices everywhere.

Signed-off-by: Adam C. Emerson <aemerson@redhat.com>
src/include/encoding.h

index 8b9c3f40f92afca2166ce3ca715e2043e2497629..943b42c8a1b3c1da81fd8771279d65e7bb8188a5 100644 (file)
@@ -19,6 +19,7 @@
 #include <deque>
 #include <vector>
 #include <string>
+#include <tuple>
 #include <boost/optional/optional_io.hpp>
 #include <boost/tuple/tuple.hpp>
 
@@ -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<typename T>
 inline void encode(const boost::optional<T> &p, bufferlist &bl)
@@ -523,7 +523,23 @@ inline void decode(boost::optional<T> &p, bufferlist::iterator &bp)
 #pragma GCC diagnostic pop
 #pragma GCC diagnostic warning "-Wpragmas"
 
-//triple tuple
+// std::tuple
+template<typename... Ts>
+inline void encode(const std::tuple<Ts...> &t, bufferlist& bl)
+{
+  ceph::for_each(t, [&bl](const auto& e) {
+      encode(e, bl);
+    });
+}
+template<typename... Ts>
+inline void decode(std::tuple<Ts...> &t, bufferlist::iterator &bp)
+{
+  ceph::for_each(t, [&bp](auto& e) {
+      decode(e, bp);
+    });
+}
+
+//triple boost::tuple
 template<class A, class B, class C>
 inline void encode(const boost::tuple<A, B, C> &t, bufferlist& bl)
 {