]> git.apps.os.sepia.ceph.com Git - ceph-ci.git/commitdiff
encoding: Move encode/decode functions into ceph namespace
authorAdam C. Emerson <aemerson@redhat.com>
Fri, 22 Dec 2017 03:41:54 +0000 (22:41 -0500)
committerAdam C. Emerson <aemerson@redhat.com>
Wed, 10 Jan 2018 19:02:09 +0000 (14:02 -0500)
This begins Part 1 of the Great Namespace Fix. Currently, encode/decode
does not handle types in namespaces properly. Mostly because people call
them as ::encode and ::decode, completely wrecking argument dependent
lookup.

By fixing encode/decode, we prepare the way to use namespaces
extensively in Ceph.

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

index a1983fa04269991406247018029a738f6269e796..b07e2ed33313f4e928c4b812484b3f54282ee6ae 100644 (file)
@@ -1517,9 +1517,9 @@ struct denc_traits<boost::none_t> {
 // These glue the new-style denc world into old-style calls to encode
 // and decode by calling into denc_traits<> methods (when present).
 
+namespace ceph {
 template<typename T, typename traits=denc_traits<T>>
-inline typename std::enable_if<traits::supported &&
-                              !traits::featured>::type encode(
+inline std::enable_if_t<traits::supported && !traits::featured> encode(
   const T& o,
   bufferlist& bl,
   uint64_t features_unused=0)
@@ -1531,8 +1531,7 @@ inline typename std::enable_if<traits::supported &&
 }
 
 template<typename T, typename traits=denc_traits<T>>
-inline typename std::enable_if<traits::supported &&
-                              traits::featured>::type encode(
+inline std::enable_if_t<traits::supported && traits::featured> encode(
   const T& o, bufferlist& bl,
   uint64_t features)
 {
@@ -1544,8 +1543,7 @@ inline typename std::enable_if<traits::supported &&
 
 template<typename T,
         typename traits=denc_traits<T>>
-inline typename std::enable_if<traits::supported &&
-                              !traits::need_contiguous>::type decode(
+inline std::enable_if_t<traits::supported && !traits::need_contiguous> decode(
   T& o,
   bufferlist::iterator& p)
 {
@@ -1573,8 +1571,7 @@ inline typename std::enable_if<traits::supported &&
 
 template<typename T,
         typename traits=denc_traits<T>>
-inline typename std::enable_if<traits::supported &&
-                              traits::need_contiguous>::type decode(
+inline std::enable_if_t<traits::supported && traits::need_contiguous> decode(
   T& o,
   bufferlist::iterator& p)
 {
@@ -1594,8 +1591,8 @@ inline typename std::enable_if<traits::supported &&
 
 // nohead variants
 template<typename T, typename traits=denc_traits<T>>
-inline typename std::enable_if<traits::supported &&
-                              !traits::featured>::type encode_nohead(
+inline std::enable_if_t<traits::supported &&
+                       !traits::featured> encode_nohead(
   const T& o,
   bufferlist& bl)
 {
@@ -1606,8 +1603,7 @@ inline typename std::enable_if<traits::supported &&
 }
 
 template<typename T, typename traits=denc_traits<T>>
-inline typename std::enable_if<traits::supported &&
-                              !traits::featured>::type decode_nohead(
+inline std::enable_if_t<traits::supported && !traits::featured> decode_nohead(
   size_t num,
   T& o,
   bufferlist::iterator& p)
@@ -1623,7 +1619,7 @@ inline typename std::enable_if<traits::supported &&
   traits::decode_nohead(num, o, cp);
   p.advance((ssize_t)cp.get_offset());
 }
-
+}
 
 
 // ----------------------------------------------------------------
index b09b08c11a59193cd27d5c00f518aec1ed8aa707..80b7d59e3be888c4dc84cd175b8faff13b9f6416 100644 (file)
 #ifndef CEPH_ENCODING_H
 #define CEPH_ENCODING_H
 
+#include <set>
+#include <map>
+#include <deque>
+#include <vector>
+#include <string>
+#include <boost/optional/optional_io.hpp>
+#include <boost/tuple/tuple.hpp>
+
+#ifndef _BACKWARD_BACKWARD_WARNING_H
+#define _BACKWARD_BACKWARD_WARNING_H   // make gcc 4.3 shut up about hash_*
+#endif
+#include "include/unordered_map.h"
+#include "include/unordered_set.h"
+
+
+
 #include "include/int_types.h"
 
 #include "include/memory.h"
@@ -28,6 +44,8 @@
 
 using namespace ceph;
 
+namespace ceph {
+
 /*
  * Notes on feature encoding:
  *
@@ -62,8 +80,8 @@ inline void decode_raw(T& t, bufferlist::iterator &p)
 }
 
 #define WRITE_RAW_ENCODER(type)                                                \
-  inline void encode(const type &v, bufferlist& bl, uint64_t features=0) { encode_raw(v, bl); } \
-  inline void decode(type &v, bufferlist::iterator& p) { __ASSERT_FUNCTION decode_raw(v, p); }
+  inline void encode(const type &v, ::ceph::bufferlist& bl, uint64_t features=0) { ::ceph::encode_raw(v, bl); } \
+  inline void decode(type &v, ::ceph::bufferlist::iterator& p) { __ASSERT_FUNCTION ::ceph::decode_raw(v, p); }
 
 WRITE_RAW_ENCODER(__u8)
 #ifndef _CHAR_IS_SIGNED
@@ -93,14 +111,14 @@ inline void decode(bool &v, bufferlist::iterator& p) {
 // int types
 
 #define WRITE_INTTYPE_ENCODER(type, etype)                             \
-  inline void encode(type v, bufferlist& bl, uint64_t features=0) {    \
+  inline void encode(type v, ::ceph::bufferlist& bl, uint64_t features=0) { \
     ceph_##etype e;                                                    \
     e = v;                                                              \
-    encode_raw(e, bl);                                                 \
+    ::ceph::encode_raw(e, bl);                                         \
   }                                                                    \
-  inline void decode(type &v, bufferlist::iterator& p) {               \
+  inline void decode(type &v, ::ceph::bufferlist::iterator& p) {       \
     ceph_##etype e;                                                    \
-    decode_raw(e, p);                                                  \
+    ::ceph::decode_raw(e, p);                                          \
     v = e;                                                             \
   }
 
@@ -128,7 +146,7 @@ WRITE_INTTYPE_ENCODER(int16_t, le16)
     snprintf(fn, sizeof(fn), ENCODE_STRINGIFY(ENCODE_DUMP_PATH) "/%s__%d.%x", #cl, getpid(), i++); \
     int fd = ::open(fn, O_WRONLY|O_TRUNC|O_CREAT, 0644);               \
     if (fd >= 0) {                                                     \
-      bufferlist sub;                                                  \
+      ::ceph::bufferlist sub;                                          \
       sub.substr_of(bl, pre_off, bl.length() - pre_off);               \
       sub.write_fd(fd);                                                        \
       ::close(fd);                                                     \
@@ -141,24 +159,24 @@ WRITE_INTTYPE_ENCODER(int16_t, le16)
 
 
 #define WRITE_CLASS_ENCODER(cl)                                                \
-  inline void encode(const cl &c, bufferlist &bl, uint64_t features=0) { \
+  inline void encode(const cl &c, ::ceph::bufferlist &bl, uint64_t features=0) { \
     ENCODE_DUMP_PRE(); c.encode(bl); ENCODE_DUMP_POST(cl); }           \
-  inline void decode(cl &c, bufferlist::iterator &p) { c.decode(p); }
+  inline void decode(cl &c, ::ceph::bufferlist::iterator &p) { c.decode(p); }
 
 #define WRITE_CLASS_MEMBER_ENCODER(cl)                                 \
-  inline void encode(const cl &c, bufferlist &bl) const {              \
+  inline void encode(const cl &c, ::ceph::bufferlist &bl) const {      \
     ENCODE_DUMP_PRE(); c.encode(bl); ENCODE_DUMP_POST(cl); }           \
-  inline void decode(cl &c, bufferlist::iterator &p) { c.decode(p); }
+  inline void decode(cl &c, ::ceph::bufferlist::iterator &p) { c.decode(p); }
 
 #define WRITE_CLASS_ENCODER_FEATURES(cl)                               \
-  inline void encode(const cl &c, bufferlist &bl, uint64_t features) { \
+  inline void encode(const cl &c, ::ceph::bufferlist &bl, uint64_t features) { \
     ENCODE_DUMP_PRE(); c.encode(bl, features); ENCODE_DUMP_POST(cl); } \
-  inline void decode(cl &c, bufferlist::iterator &p) { c.decode(p); }
+  inline void decode(cl &c, ::ceph::bufferlist::iterator &p) { c.decode(p); }
 
 #define WRITE_CLASS_ENCODER_OPTIONAL_FEATURES(cl)                              \
-  inline void encode(const cl &c, bufferlist &bl, uint64_t features = 0) {     \
+  inline void encode(const cl &c, ::ceph::bufferlist &bl, uint64_t features = 0) { \
     ENCODE_DUMP_PRE(); c.encode(bl, features); ENCODE_DUMP_POST(cl); } \
-  inline void decode(cl &c, bufferlist::iterator &p) { c.decode(p); }
+  inline void decode(cl &c, ::ceph::bufferlist::iterator &p) { c.decode(p); }
 
 
 // string
@@ -269,19 +287,189 @@ inline void decode(T &o, bufferlist& bl)
 // -----------------------------
 // STL container types
 
-#include <set>
-#include <map>
-#include <deque>
-#include <vector>
-#include <string>
-#include <boost/optional/optional_io.hpp>
-#include <boost/tuple/tuple.hpp>
-
-#ifndef _BACKWARD_BACKWARD_WARNING_H
-#define _BACKWARD_BACKWARD_WARNING_H   // make gcc 4.3 shut up about hash_*
-#endif
-#include "include/unordered_map.h"
-#include "include/unordered_set.h"
+template<typename T>
+inline void encode(const boost::optional<T> &p, bufferlist &bl);
+template<typename T>
+inline void decode(boost::optional<T> &p, bufferlist::iterator &bp);
+template<class A, class B, class C>
+inline void encode(const boost::tuple<A, B, C> &t, bufferlist& bl);
+template<class A, class B, class C>
+inline void decode(boost::tuple<A, B, C> &t, bufferlist::iterator &bp);
+template<class A, class B,
+        typename a_traits=denc_traits<A>, typename b_traits=denc_traits<B>>
+inline std::enable_if_t<!a_traits::supported || !b_traits::supported>
+encode(const std::pair<A,B> &p, bufferlist &bl, uint64_t features);
+template<class A, class B,
+        typename a_traits=denc_traits<A>, typename b_traits=denc_traits<B>>
+inline std::enable_if_t<!a_traits::supported ||
+                       !b_traits::supported>
+encode(const std::pair<A,B> &p, bufferlist &bl);
+template<class A, class B,
+        typename a_traits=denc_traits<A>, typename b_traits=denc_traits<B>>
+inline std::enable_if_t<!a_traits::supported ||
+                       !b_traits::supported>
+decode(std::pair<A,B> &pa, bufferlist::iterator &p);
+template<class T, class Alloc, typename traits=denc_traits<T>>
+inline std::enable_if_t<!traits::supported>
+encode(const std::list<T, Alloc>& ls, bufferlist& bl);
+template<class T, class Alloc, typename traits=denc_traits<T>>
+inline std::enable_if_t<!traits::supported>
+encode(const std::list<T,Alloc>& ls, bufferlist& bl, uint64_t features);
+template<class T, class Alloc, typename traits=denc_traits<T>>
+inline std::enable_if_t<!traits::supported>
+decode(std::list<T,Alloc>& ls, bufferlist::iterator& p);
+template<class T, class Alloc>
+inline void encode(const std::list<ceph::shared_ptr<T>, Alloc>& ls,
+                  bufferlist& bl);
+template<class T, class Alloc>
+inline void encode(const std::list<ceph::shared_ptr<T>, Alloc>& ls,
+                  bufferlist& bl, uint64_t features);
+template<class T, class Alloc>
+inline void decode(std::list<ceph::shared_ptr<T>, Alloc>& ls,
+                  bufferlist::iterator& p);
+template<class T, class Comp, class Alloc, typename traits=denc_traits<T>>
+inline std::enable_if_t<!traits::supported>
+encode(const std::set<T,Comp,Alloc>& s, bufferlist& bl);
+template<class T, class Comp, class Alloc, typename traits=denc_traits<T>>
+inline std::enable_if_t<!traits::supported>
+decode(std::set<T,Comp,Alloc>& s, bufferlist::iterator& p);
+template<class T, class Comp, class Alloc, typename traits=denc_traits<T>>
+inline std::enable_if_t<!traits::supported>
+encode_nohead(const std::set<T,Comp,Alloc>& s, bufferlist& bl);
+template<class T, class Comp, class Alloc, typename traits=denc_traits<T>>
+inline std::enable_if_t<!traits::supported>
+decode_nohead(int len, std::set<T,Comp,Alloc>& s, bufferlist::iterator& p);
+template<class T, class Comp, class Alloc, typename traits=denc_traits<T>>
+inline std::enable_if_t<!traits::supported>
+encode(const boost::container::flat_set<T, Comp, Alloc>& s, bufferlist& bl);
+template<class T, class Comp, class Alloc, typename traits=denc_traits<T>>
+inline std::enable_if_t<!traits::supported>
+decode(boost::container::flat_set<T, Comp, Alloc>& s, bufferlist::iterator& p);
+template<class T, class Comp, class Alloc, typename traits=denc_traits<T>>
+inline std::enable_if_t<!traits::supported>
+encode_nohead(const boost::container::flat_set<T, Comp, Alloc>& s,
+             bufferlist& bl);
+template<class T, class Comp, class Alloc, typename traits=denc_traits<T>>
+inline std::enable_if_t<!traits::supported>
+decode_nohead(int len, boost::container::flat_set<T, Comp, Alloc>& s,
+             bufferlist::iterator& p);
+template<class T, class Comp, class Alloc>
+inline void encode(const std::multiset<T,Comp,Alloc>& s, bufferlist& bl);
+template<class T, class Comp, class Alloc>
+inline void decode(std::multiset<T,Comp,Alloc>& s, bufferlist::iterator& p);
+template<class T, class Alloc, typename traits=denc_traits<T>>
+inline std::enable_if_t<!traits::supported>
+encode(const std::vector<T,Alloc>& v, bufferlist& bl, uint64_t features);
+template<class T, class Alloc, typename traits=denc_traits<T>>
+inline std::enable_if_t<!traits::supported>
+encode(const std::vector<T,Alloc>& v, bufferlist& bl);
+template<class T, class Alloc, typename traits=denc_traits<T>>
+inline std::enable_if_t<!traits::supported>
+decode(std::vector<T,Alloc>& v, bufferlist::iterator& p);
+template<class T, class Alloc, typename traits=denc_traits<T>>
+inline std::enable_if_t<!traits::supported>
+encode_nohead(const std::vector<T,Alloc>& v, bufferlist& bl);
+template<class T, class Alloc, typename traits=denc_traits<T>>
+inline std::enable_if_t<!traits::supported>
+decode_nohead(int len, std::vector<T,Alloc>& v, bufferlist::iterator& p);
+template<class T,class Alloc>
+inline void encode(const std::vector<ceph::shared_ptr<T>,Alloc>& v,
+                  bufferlist& bl,
+                  uint64_t features);
+template<class T, class Alloc>
+inline void encode(const std::vector<ceph::shared_ptr<T>,Alloc>& v,
+                  bufferlist& bl);
+template<class T, class Alloc>
+inline void decode(std::vector<ceph::shared_ptr<T>,Alloc>& v,
+                  bufferlist::iterator& p);
+template<class T, class U, class Comp, class Alloc,
+        typename t_traits=denc_traits<T>, typename u_traits=denc_traits<U>>
+inline std::enable_if_t<!t_traits::supported ||
+                       !u_traits::supported>
+encode(const std::map<T,U,Comp,Alloc>& m, bufferlist& bl);
+template<class T, class U, class Comp, class Alloc,
+        typename t_traits=denc_traits<T>, typename u_traits=denc_traits<U>>
+inline std::enable_if_t<!t_traits::supported || !u_traits::supported>
+encode(const std::map<T,U,Comp,Alloc>& m, bufferlist& bl, uint64_t features);
+template<class T, class U, class Comp, class Alloc,
+        typename t_traits=denc_traits<T>, typename u_traits=denc_traits<U>>
+inline std::enable_if_t<!t_traits::supported || !u_traits::supported>
+decode(std::map<T,U,Comp,Alloc>& m, bufferlist::iterator& p);
+template<class T, class U, class Comp, class Alloc>
+inline void decode_noclear(std::map<T,U,Comp,Alloc>& m, bufferlist::iterator& p);
+template<class T, class U, class Comp, class Alloc,
+        typename t_traits=denc_traits<T>, typename u_traits=denc_traits<U>>
+inline std::enable_if_t<!t_traits::supported || !u_traits::supported>
+encode_nohead(const std::map<T,U,Comp,Alloc>& m, bufferlist& bl);
+template<class T, class U, class Comp, class Alloc,
+        typename t_traits=denc_traits<T>, typename u_traits=denc_traits<U>>
+inline std::enable_if_t<!t_traits::supported || !u_traits::supported>
+encode_nohead(const std::map<T,U,Comp,Alloc>& m, bufferlist& bl, uint64_t features);
+template<class T, class U, class Comp, class Alloc,
+        typename t_traits=denc_traits<T>, typename u_traits=denc_traits<U>>
+inline std::enable_if_t<!t_traits::supported || !u_traits::supported>
+decode_nohead(int n, std::map<T,U,Comp,Alloc>& m, bufferlist::iterator& p);
+template<class T, class U, class Comp, class Alloc,
+        typename t_traits=denc_traits<T>, typename u_traits=denc_traits<U>>
+  inline std::enable_if_t<!t_traits::supported || !u_traits::supported>
+encode(const boost::container::flat_map<T,U,Comp,Alloc>& m, bufferlist& bl);
+template<class T, class U, class Comp, class Alloc,
+        typename t_traits=denc_traits<T>, typename u_traits=denc_traits<U>>
+inline std::enable_if_t<!t_traits::supported || !u_traits::supported>
+encode(const boost::container::flat_map<T,U,Comp,Alloc>& m, bufferlist& bl,
+       uint64_t features);
+template<class T, class U, class Comp, class Alloc,
+        typename t_traits=denc_traits<T>, typename u_traits=denc_traits<U>>
+inline std::enable_if_t<!t_traits::supported || !u_traits::supported>
+decode(boost::container::flat_map<T,U,Comp,Alloc>& m, bufferlist::iterator& p);
+template<class T, class U, class Comp, class Alloc>
+inline void decode_noclear(boost::container::flat_map<T,U,Comp,Alloc>& m,
+                          bufferlist::iterator& p);
+template<class T, class U, class Comp, class Alloc,
+        typename t_traits=denc_traits<T>, typename u_traits=denc_traits<U>>
+inline std::enable_if_t<!t_traits::supported || !u_traits::supported>
+encode_nohead(const boost::container::flat_map<T,U,Comp,Alloc>& m,
+             bufferlist& bl);
+template<class T, class U, class Comp, class Alloc,
+        typename t_traits=denc_traits<T>, typename u_traits=denc_traits<U>>
+inline std::enable_if_t<!t_traits::supported || !u_traits::supported>
+encode_nohead(const boost::container::flat_map<T,U,Comp,Alloc>& m,
+             bufferlist& bl, uint64_t features);
+template<class T, class U, class Comp, class Alloc,
+        typename t_traits=denc_traits<T>, typename u_traits=denc_traits<U>>
+inline std::enable_if_t<!t_traits::supported || !u_traits::supported>
+decode_nohead(int n, boost::container::flat_map<T,U,Comp,Alloc>& m,
+             bufferlist::iterator& p);
+template<class T, class U, class Comp, class Alloc>
+inline void encode(const std::multimap<T,U,Comp,Alloc>& m, bufferlist& bl);
+template<class T, class U, class Comp, class Alloc>
+inline void decode(std::multimap<T,U,Comp,Alloc>& m, bufferlist::iterator& p);
+template<class T, class U, class Hash, class Pred, class Alloc>
+inline void encode(const unordered_map<T,U,Hash,Pred,Alloc>& m, bufferlist& bl,
+                  uint64_t features);
+template<class T, class U, class Hash, class Pred, class Alloc>
+inline void encode(const unordered_map<T,U,Hash,Pred,Alloc>& m, bufferlist& bl);
+template<class T, class U, class Hash, class Pred, class Alloc>
+inline void decode(unordered_map<T,U,Hash,Pred,Alloc>& m, bufferlist::iterator& p);
+template<class T, class Hash, class Pred, class Alloc>
+inline void encode(const ceph::unordered_set<T,Hash,Pred,Alloc>& m, bufferlist& bl);
+template<class T, class Hash, class Pred, class Alloc>
+inline void decode(ceph::unordered_set<T,Hash,Pred,Alloc>& m, bufferlist::iterator& p);
+template<class T, class Alloc>
+inline void encode(const std::deque<T,Alloc>& ls, bufferlist& bl, uint64_t features);
+template<class T, class Alloc>
+inline void encode(const std::deque<T,Alloc>& ls, bufferlist& bl);
+template<class T, class Alloc>
+inline void decode(std::deque<T,Alloc>& ls, bufferlist::iterator& p);
+template<class T, size_t N, typename traits = denc_traits<T>>
+inline std::enable_if_t<!traits::supported>
+encode(const std::array<T, N>& v, bufferlist& bl, uint64_t features);
+template<class T, size_t N, typename traits = denc_traits<T>>
+inline std::enable_if_t<!traits::supported>
+encode(const std::array<T, N>& v, bufferlist& bl);
+template<class T, size_t N, typename traits = denc_traits<T>>
+inline std::enable_if_t<!traits::supported>
+decode(std::array<T, N>& v, bufferlist::iterator& p);
 
 
 // boost optional
@@ -289,7 +477,7 @@ template<typename T>
 inline void encode(const boost::optional<T> &p, bufferlist &bl)
 {
   __u8 present = static_cast<bool>(p);
-  ::encode(present, bl);
+  encode(present, bl);
   if (p)
     encode(p.get(), bl);
 }
@@ -301,7 +489,7 @@ template<typename T>
 inline void decode(boost::optional<T> &p, bufferlist::iterator &bp)
 {
   __u8 present;
-  ::decode(present, bp);
+  decode(present, bp);
   if (present) {
     p = T{};
     decode(p.get(), bp);
@@ -330,27 +518,25 @@ inline void decode(boost::tuple<A, B, C> &t, bufferlist::iterator &bp)
 
 // std::pair<A,B>
 template<class A, class B,
-        typename a_traits=denc_traits<A>, typename b_traits=denc_traits<B>>
-inline typename std::enable_if<!a_traits::supported ||
-                              !b_traits::supported>::type
+        typename a_traits, typename b_traits>
+inline std::enable_if_t<!a_traits::supported || !b_traits::supported>
   encode(const std::pair<A,B> &p, bufferlist &bl, uint64_t features)
 {
   encode(p.first, bl, features);
   encode(p.second, bl, features);
 }
 template<class A, class B,
-        typename a_traits=denc_traits<A>, typename b_traits=denc_traits<B>>
-inline typename std::enable_if<!a_traits::supported ||
-                              !b_traits::supported>::type
+        typename a_traits, typename b_traits>
+inline std::enable_if_t<!a_traits::supported ||
+                       !b_traits::supported>
   encode(const std::pair<A,B> &p, bufferlist &bl)
 {
   encode(p.first, bl);
   encode(p.second, bl);
 }
-template<class A, class B,
-        typename a_traits=denc_traits<A>, typename b_traits=denc_traits<B>>
-inline typename std::enable_if<!a_traits::supported ||
-                              !b_traits::supported>::type
+template<class A, class B, typename a_traits, typename b_traits>
+inline std::enable_if_t<!a_traits::supported ||
+                       !b_traits::supported>
   decode(std::pair<A,B> &pa, bufferlist::iterator &p)
 {
   decode(pa.first, p);
@@ -358,8 +544,8 @@ inline typename std::enable_if<!a_traits::supported ||
 }
 
 // std::list<T>
-template<class T, class Alloc, typename traits=denc_traits<T>>
-inline typename std::enable_if<!traits::supported>::type
+template<class T, class Alloc, typename traits>
+inline std::enable_if_t<!traits::supported>
   encode(const std::list<T, Alloc>& ls, bufferlist& bl)
 {
   __u32 n = (__u32)(ls.size());  // c++11 std::list::size() is O(1)
@@ -367,8 +553,8 @@ inline typename std::enable_if<!traits::supported>::type
   for (auto p = ls.begin(); p != ls.end(); ++p)
     encode(*p, bl);
 }
-template<class T, class Alloc, typename traits=denc_traits<T>>
-inline typename std::enable_if<!traits::supported>::type
+template<class T, class Alloc, typename traits>
+inline std::enable_if_t<!traits::supported>
   encode(const std::list<T,Alloc>& ls, bufferlist& bl, uint64_t features)
 {
   // should i pre- or post- count?
@@ -390,8 +576,8 @@ inline typename std::enable_if<!traits::supported>::type
       encode(*p, bl, features);
   }
 }
-template<class T, class Alloc, typename traits=denc_traits<T>>
-inline typename std::enable_if<!traits::supported>::type
+template<class T, class Alloc, typename traits>
+inline std::enable_if_t<!traits::supported>
   decode(std::list<T,Alloc>& ls, bufferlist::iterator& p)
 {
   __u32 n;
@@ -438,8 +624,8 @@ inline void decode(std::list<ceph::shared_ptr<T>, Alloc>& ls,
 }
 
 // std::set<T>
-template<class T, class Comp, class Alloc, typename traits=denc_traits<T>>
-inline typename std::enable_if<!traits::supported>::type
+template<class T, class Comp, class Alloc, typename traits>
+inline std::enable_if_t<!traits::supported>
   encode(const std::set<T,Comp,Alloc>& s, bufferlist& bl)
 {
   __u32 n = (__u32)(s.size());
@@ -447,8 +633,8 @@ inline typename std::enable_if<!traits::supported>::type
   for (auto p = s.begin(); p != s.end(); ++p)
     encode(*p, bl);
 }
-template<class T, class Comp, class Alloc, typename traits=denc_traits<T>>
-inline typename std::enable_if<!traits::supported>::type
+template<class T, class Comp, class Alloc, typename traits>
+inline std::enable_if_t<!traits::supported>
   decode(std::set<T,Comp,Alloc>& s, bufferlist::iterator& p)
 {
   __u32 n;
@@ -461,15 +647,15 @@ inline typename std::enable_if<!traits::supported>::type
   }
 }
 
-template<class T, class Comp, class Alloc, typename traits=denc_traits<T>>
+template<class T, class Comp, class Alloc, typename traits>
 inline typename std::enable_if<!traits::supported>::type
   encode_nohead(const std::set<T,Comp,Alloc>& s, bufferlist& bl)
 {
   for (auto p = s.begin(); p != s.end(); ++p)
     encode(*p, bl);
 }
-template<class T, class Comp, class Alloc, typename traits=denc_traits<T>>
-inline typename std::enable_if<!traits::supported>::type
+template<class T, class Comp, class Alloc, typename traits>
+inline std::enable_if_t<!traits::supported>
   decode_nohead(int len, std::set<T,Comp,Alloc>& s, bufferlist::iterator& p)
 {
   for (int i=0; i<len; i++) {
@@ -480,8 +666,8 @@ inline typename std::enable_if<!traits::supported>::type
 }
 
 // boost::container::flat_set<T>
-template<class T, class Comp, class Alloc, typename traits=denc_traits<T>>
-inline typename std::enable_if<!traits::supported>::type
+template<class T, class Comp, class Alloc, typename traits>
+inline std::enable_if_t<!traits::supported>
 encode(const boost::container::flat_set<T, Comp, Alloc>& s, bufferlist& bl)
 {
   __u32 n = (__u32)(s.size());
@@ -489,8 +675,8 @@ encode(const boost::container::flat_set<T, Comp, Alloc>& s, bufferlist& bl)
   for (const auto& e : s)
     encode(e, bl);
 }
-template<class T, class Comp, class Alloc, typename traits=denc_traits<T>>
-inline typename std::enable_if<!traits::supported>::type
+template<class T, class Comp, class Alloc, typename traits>
+inline std::enable_if_t<!traits::supported>
 decode(boost::container::flat_set<T, Comp, Alloc>& s, bufferlist::iterator& p)
 {
   __u32 n;
@@ -504,16 +690,16 @@ decode(boost::container::flat_set<T, Comp, Alloc>& s, bufferlist::iterator& p)
   }
 }
 
-template<class T, class Comp, class Alloc, typename traits=denc_traits<T>>
-inline typename std::enable_if<!traits::supported>::type
+template<class T, class Comp, class Alloc, typename traits>
+inline std::enable_if_t<!traits::supported>
 encode_nohead(const boost::container::flat_set<T, Comp, Alloc>& s,
              bufferlist& bl)
 {
   for (const auto& e : s)
     encode(e, bl);
 }
-template<class T, class Comp, class Alloc, typename traits=denc_traits<T>>
-inline typename std::enable_if<!traits::supported>::type
+template<class T, class Comp, class Alloc, typename traits>
+inline std::enable_if_t<!traits::supported>
 decode_nohead(int len, boost::container::flat_set<T, Comp, Alloc>& s,
              bufferlist::iterator& p)
 {
@@ -547,28 +733,8 @@ inline void decode(std::multiset<T,Comp,Alloc>& s, bufferlist::iterator& p)
   }
 }
 
-// vector (pointers)
-/*template<class T>
-inline void encode(const std::vector<T*>& v, bufferlist& bl)
-{
-  __u32 n = v.size();
-  encode(n, bl);
-  for (typename std::vector<T*>::const_iterator p = v.begin(); p != v.end(); ++p)
-    encode(**p, bl);
-}
-template<class T>
-inline void decode(std::vector<T*>& v, bufferlist::iterator& p)
-{
-  __u32 n;
-  decode(n, p);
-  v.resize(n);
-  for (__u32 i=0; i<n; i++) 
-    v[i] = new T(p);
-}
-*/
-// std::vector<T>
-template<class T, class Alloc, typename traits=denc_traits<T>>
-inline typename std::enable_if<!traits::supported>::type
+template<class T, class Alloc, typename traits>
+inline std::enable_if_t<!traits::supported>
   encode(const std::vector<T,Alloc>& v, bufferlist& bl, uint64_t features)
 {
   __u32 n = (__u32)(v.size());
@@ -576,8 +742,8 @@ inline typename std::enable_if<!traits::supported>::type
   for (auto p = v.begin(); p != v.end(); ++p)
     encode(*p, bl, features);
 }
-template<class T, class Alloc, typename traits=denc_traits<T>>
-inline typename std::enable_if<!traits::supported>::type
+template<class T, class Alloc, typename traits>
+inline std::enable_if_t<!traits::supported>
   encode(const std::vector<T,Alloc>& v, bufferlist& bl)
 {
   __u32 n = (__u32)(v.size());
@@ -585,8 +751,8 @@ inline typename std::enable_if<!traits::supported>::type
   for (auto p = v.begin(); p != v.end(); ++p)
     encode(*p, bl);
 }
-template<class T, class Alloc, typename traits=denc_traits<T>>
-inline typename std::enable_if<!traits::supported>::type
+template<class T, class Alloc, typename traits>
+inline std::enable_if_t<!traits::supported>
   decode(std::vector<T,Alloc>& v, bufferlist::iterator& p)
 {
   __u32 n;
@@ -596,15 +762,15 @@ inline typename std::enable_if<!traits::supported>::type
     decode(v[i], p);
 }
 
-template<class T, class Alloc, typename traits=denc_traits<T>>
-inline typename std::enable_if<!traits::supported>::type
+template<class T, class Alloc, typename traits>
+inline std::enable_if_t<!traits::supported>
   encode_nohead(const std::vector<T,Alloc>& v, bufferlist& bl)
 {
   for (auto p = v.begin(); p != v.end(); ++p)
     encode(*p, bl);
 }
-template<class T, class Alloc, typename traits=denc_traits<T>>
-inline typename std::enable_if<!traits::supported>::type
+template<class T, class Alloc, typename traits>
+inline std::enable_if_t<!traits::supported>
   decode_nohead(int len, std::vector<T,Alloc>& v, bufferlist::iterator& p)
 {
   v.resize(len);
@@ -651,36 +817,11 @@ inline void decode(std::vector<ceph::shared_ptr<T>,Alloc>& v,
   }
 }
 
-// map (pointers)
-/*
-template<class T, class U>
-inline void encode(const std::map<T,U*>& m, bufferlist& bl)
-{
-  __u32 n = m.size();
-  encode(n, bl);
-  for (typename std::map<T,U*>::const_iterator p = m.begin(); p != m.end(); ++p) {
-    encode(p->first, bl);
-    encode(*p->second, bl);
-  }
-}
-template<class T, class U>
-inline void decode(std::map<T,U*>& m, bufferlist::iterator& p)
-{
-  __u32 n;
-  decode(n, p);
-  m.clear();
-  while (n--) {
-    T k;
-    decode(k, p);
-    m[k] = new U(p);
-  }
-  }*/
-
 // map
 template<class T, class U, class Comp, class Alloc,
-        typename t_traits=denc_traits<T>, typename u_traits=denc_traits<U>>
-inline typename std::enable_if<!t_traits::supported ||
-                                !u_traits::supported>::type
+        typename t_traits, typename u_traits>
+inline std::enable_if_t<!t_traits::supported ||
+                       !u_traits::supported>
   encode(const std::map<T,U,Comp,Alloc>& m, bufferlist& bl)
 {
   __u32 n = (__u32)(m.size());
@@ -691,9 +832,8 @@ inline typename std::enable_if<!t_traits::supported ||
   }
 }
 template<class T, class U, class Comp, class Alloc,
-        typename t_traits=denc_traits<T>, typename u_traits=denc_traits<U>>
-inline typename std::enable_if<!t_traits::supported ||
-                                !u_traits::supported>::type
+        typename t_traits, typename u_traits>
+inline std::enable_if_t<!t_traits::supported || !u_traits::supported>
   encode(const std::map<T,U,Comp,Alloc>& m, bufferlist& bl, uint64_t features)
 {
   __u32 n = (__u32)(m.size());
@@ -704,9 +844,8 @@ inline typename std::enable_if<!t_traits::supported ||
   }
 }
 template<class T, class U, class Comp, class Alloc,
-        typename t_traits=denc_traits<T>, typename u_traits=denc_traits<U>>
-inline typename std::enable_if<!t_traits::supported ||
-                                !u_traits::supported>::type
+        typename t_traits, typename u_traits>
+inline std::enable_if_t<!t_traits::supported || !u_traits::supported>
   decode(std::map<T,U,Comp,Alloc>& m, bufferlist::iterator& p)
 {
   __u32 n;
@@ -730,9 +869,8 @@ inline void decode_noclear(std::map<T,U,Comp,Alloc>& m, bufferlist::iterator& p)
   }
 }
 template<class T, class U, class Comp, class Alloc,
-        typename t_traits=denc_traits<T>, typename u_traits=denc_traits<U>>
-inline typename std::enable_if<!t_traits::supported ||
-                                !u_traits::supported>::type
+        typename t_traits, typename u_traits>
+inline std::enable_if_t<!t_traits::supported || !u_traits::supported>
   encode_nohead(const std::map<T,U,Comp,Alloc>& m, bufferlist& bl)
 {
   for (auto p = m.begin(); p != m.end(); ++p) {
@@ -741,9 +879,8 @@ inline typename std::enable_if<!t_traits::supported ||
   }
 }
 template<class T, class U, class Comp, class Alloc,
-        typename t_traits=denc_traits<T>, typename u_traits=denc_traits<U>>
-inline typename std::enable_if<!t_traits::supported ||
-                                !u_traits::supported>::type
+        typename t_traits, typename u_traits>
+inline std::enable_if_t<!t_traits::supported || !u_traits::supported>
   encode_nohead(const std::map<T,U,Comp,Alloc>& m, bufferlist& bl, uint64_t features)
 {
   for (auto p = m.begin(); p != m.end(); ++p) {
@@ -752,9 +889,8 @@ inline typename std::enable_if<!t_traits::supported ||
   }
 }
 template<class T, class U, class Comp, class Alloc,
-        typename t_traits=denc_traits<T>, typename u_traits=denc_traits<U>>
-inline typename std::enable_if<!t_traits::supported ||
-                                !u_traits::supported>::type
+        typename t_traits, typename u_traits>
+inline std::enable_if_t<!t_traits::supported || !u_traits::supported>
   decode_nohead(int n, std::map<T,U,Comp,Alloc>& m, bufferlist::iterator& p)
 {
   m.clear();
@@ -767,9 +903,8 @@ inline typename std::enable_if<!t_traits::supported ||
 
 // boost::container::flat-map
 template<class T, class U, class Comp, class Alloc,
-        typename t_traits=denc_traits<T>, typename u_traits=denc_traits<U>>
-  inline typename std::enable_if<!t_traits::supported ||
-                                !u_traits::supported>::type
+        typename t_traits, typename u_traits>
+  inline std::enable_if_t<!t_traits::supported || !u_traits::supported>
   encode(const boost::container::flat_map<T,U,Comp,Alloc>& m, bufferlist& bl)
 {
   __u32 n = (__u32)(m.size());
@@ -781,9 +916,8 @@ template<class T, class U, class Comp, class Alloc,
   }
 }
 template<class T, class U, class Comp, class Alloc,
-        typename t_traits=denc_traits<T>, typename u_traits=denc_traits<U>>
-  inline typename std::enable_if<!t_traits::supported ||
-                                !u_traits::supported>::type
+        typename t_traits, typename u_traits>
+  inline std::enable_if_t<!t_traits::supported || !u_traits::supported>
   encode(const boost::container::flat_map<T,U,Comp,Alloc>& m, bufferlist& bl,
         uint64_t features)
 {
@@ -795,9 +929,8 @@ template<class T, class U, class Comp, class Alloc,
   }
 }
 template<class T, class U, class Comp, class Alloc,
-        typename t_traits=denc_traits<T>, typename u_traits=denc_traits<U>>
-  inline typename std::enable_if<!t_traits::supported ||
-                                !u_traits::supported>::type
+        typename t_traits, typename u_traits>
+  inline std::enable_if_t<!t_traits::supported || !u_traits::supported>
   decode(boost::container::flat_map<T,U,Comp,Alloc>& m, bufferlist::iterator& p)
 {
   __u32 n;
@@ -824,9 +957,8 @@ inline void decode_noclear(boost::container::flat_map<T,U,Comp,Alloc>& m,
   }
 }
 template<class T, class U, class Comp, class Alloc,
-        typename t_traits=denc_traits<T>, typename u_traits=denc_traits<U>>
-  inline typename std::enable_if<!t_traits::supported ||
-                                !u_traits::supported>::type
+        typename t_traits, typename u_traits>
+  inline std::enable_if_t<!t_traits::supported || !u_traits::supported>
   encode_nohead(const boost::container::flat_map<T,U,Comp,Alloc>& m,
                bufferlist& bl)
 {
@@ -836,9 +968,8 @@ template<class T, class U, class Comp, class Alloc,
   }
 }
 template<class T, class U, class Comp, class Alloc,
-        typename t_traits=denc_traits<T>, typename u_traits=denc_traits<U>>
-  inline typename std::enable_if<!t_traits::supported ||
-                                !u_traits::supported>::type
+        typename t_traits, typename u_traits>
+  inline std::enable_if_t<!t_traits::supported || !u_traits::supported>
   encode_nohead(const boost::container::flat_map<T,U,Comp,Alloc>& m,
                bufferlist& bl, uint64_t features)
 {
@@ -848,9 +979,8 @@ template<class T, class U, class Comp, class Alloc,
   }
 }
 template<class T, class U, class Comp, class Alloc,
-        typename t_traits=denc_traits<T>, typename u_traits=denc_traits<U>>
-inline typename std::enable_if<!t_traits::supported ||
-                                !u_traits::supported>::type
+        typename t_traits, typename u_traits>
+inline std::enable_if_t<!t_traits::supported || !u_traits::supported>
   decode_nohead(int n, boost::container::flat_map<T,U,Comp,Alloc>& m,
                bufferlist::iterator& p)
 {
@@ -975,28 +1105,28 @@ inline void decode(std::deque<T,Alloc>& ls, bufferlist::iterator& p)
 }
 
 // std::array<T, N>
-template<class T, size_t N, typename traits = denc_traits<T>>
-inline typename std::enable_if<!traits::supported>::type
+template<class T, size_t N, typename traits>
+inline std::enable_if_t<!traits::supported>
 encode(const std::array<T, N>& v, bufferlist& bl, uint64_t features)
 {
   for (const auto& e : v)
     encode(e, bl, features);
 }
-template<class T, size_t N, typename traits = denc_traits<T>>
-inline typename std::enable_if<!traits::supported>::type
+template<class T, size_t N, typename traits>
+inline std::enable_if_t<!traits::supported>
 encode(const std::array<T, N>& v, bufferlist& bl)
 {
   for (const auto& e : v)
     encode(e, bl);
 }
-template<class T, size_t N, typename traits = denc_traits<T>>
-inline typename std::enable_if<!traits::supported>::type
+template<class T, size_t N, typename traits>
+inline std::enable_if_t<!traits::supported>
 decode(std::array<T, N>& v, bufferlist::iterator& p)
 {
   for (auto& e : v)
     decode(e, p);
 }
-
+}
 
 /*
  * guards
@@ -1010,15 +1140,16 @@ decode(std::array<T, N>& v, bufferlist::iterator& p)
  * @param bl bufferlist to encode to
  */
 #define ENCODE_START(v, compat, bl)                         \
+  using ::ceph::encode;                                             \
   __u8 struct_v = v, struct_compat = compat;                \
-  ::encode(struct_v, (bl));                                 \
-  ::encode(struct_compat, (bl));                            \
-  buffer::list::iterator struct_compat_it = (bl).end();             \
+  encode(struct_v, (bl));                                   \
+  encode(struct_compat, (bl));                      \
+  ::ceph::buffer::list::iterator struct_compat_it = (bl).end();        \
   struct_compat_it.advance(-1);                                     \
   ceph_le32 struct_len;                                             \
   struct_len = 0;                                            \
-  ::encode(struct_len, (bl));                               \
-  buffer::list::iterator struct_len_it = (bl).end();        \
+  encode(struct_len, (bl));                                 \
+  ::ceph::buffer::list::iterator struct_len_it = (bl).end(); \
   struct_len_it.advance(-4);                                \
   do {
 
@@ -1054,7 +1185,7 @@ decode(std::array<T, N>& v, bufferlist::iterator& p)
  */
 #define DECODE_OLDEST(oldestv)                                         \
   if (struct_v < oldestv)                                              \
-    throw buffer::malformed_input(DECODE_ERR_OLDVERSION(__PRETTY_FUNCTION__, v, oldestv)); 
+    throw ::ceph::buffer::malformed_input(DECODE_ERR_OLDVERSION(__PRETTY_FUNCTION__, v, oldestv)); 
 
 /**
  * start a decoding block
@@ -1064,23 +1195,25 @@ decode(std::array<T, N>& v, bufferlist::iterator& p)
  */
 #define DECODE_START(v, bl)                                            \
   __u8 struct_v, struct_compat;                                                \
-  ::decode(struct_v, bl);                                              \
-  ::decode(struct_compat, bl);                                         \
+  using ::ceph::decode;                                                        \
+  decode(struct_v, bl);                                                \
+  decode(struct_compat, bl);                                           \
   if (v < struct_compat)                                               \
     throw buffer::malformed_input(DECODE_ERR_OLDVERSION(__PRETTY_FUNCTION__, v, struct_compat)); \
   __u32 struct_len;                                                    \
-  ::decode(struct_len, bl);                                            \
+  decode(struct_len, bl);                                              \
   if (struct_len > bl.get_remaining())                                 \
-    throw buffer::malformed_input(DECODE_ERR_PAST(__PRETTY_FUNCTION__)); \
+    throw ::ceph::buffer::malformed_input(DECODE_ERR_PAST(__PRETTY_FUNCTION__)); \
   unsigned struct_end = bl.get_off() + struct_len;                     \
   do {
 
 #define __DECODE_START_LEGACY_COMPAT_LEN(v, compatv, lenv, skip_v, bl) \
+  using ::ceph::decode;                                                        \
   __u8 struct_v;                                                       \
-  ::decode(struct_v, bl);                                              \
+  decode(struct_v, bl);                                                \
   if (struct_v >= compatv) {                                           \
     __u8 struct_compat;                                                        \
-    ::decode(struct_compat, bl);                                       \
+    decode(struct_compat, bl);                                 \
     if (v < struct_compat)                                             \
       throw buffer::malformed_input(DECODE_ERR_OLDVERSION(__PRETTY_FUNCTION__, v, struct_compat)); \
   } else if (skip_v) {                                                 \
@@ -1091,7 +1224,7 @@ decode(std::array<T, N>& v, bufferlist::iterator& p)
   unsigned struct_end = 0;                                             \
   if (struct_v >= lenv) {                                              \
     __u32 struct_len;                                                  \
-    ::decode(struct_len, bl);                                          \
+    decode(struct_len, bl);                                            \
     if (struct_len > bl.get_remaining())                               \
       throw buffer::malformed_input(DECODE_ERR_PAST(__PRETTY_FUNCTION__)); \
     struct_end = bl.get_off() + struct_len;                            \
@@ -1152,6 +1285,8 @@ decode(std::array<T, N>& v, bufferlist::iterator& p)
       bl.advance(struct_end - bl.get_off());                           \
   }
 
+namespace ceph {
+
 /*
  * Encoders/decoders to read from current offset in a file handle and
  * encode/decode the data according to argument types.
@@ -1179,5 +1314,11 @@ inline ssize_t decode_file(int fd, bufferptr &bp)
   decode(bp, bli);                                                                                                  
   return bl.length();
 }
+}
+
+using ceph::encode;
+using ceph::decode;
+using ceph::encode_nohead;
+using ceph::decode_nohead;
 
 #endif
index 29598503d02de646c70d2eb34a4cbd8ad47c870f..5ed96bd780345a7e78d3c09d4ab09821abe462d7 100644 (file)
@@ -93,7 +93,7 @@ public:
     ::encode(EVENT_NEW_ENCODING, bl);
     ENCODE_START(1, 1, bl)
     ::encode(_type, bl);
-    encode(bl, features);
+    this->encode(bl, features);
     ENCODE_FINISH(bl);
   }
 
index 21e31d4fab9f423804b2502e1cfeefdd1a991fc7..f05789af43f358527b6643c209a656e207941e25 100644 (file)
@@ -234,6 +234,7 @@ TEST(EncodingRoundTrip, MultimapConstructorCounter) {
   EXPECT_EQ(my_val_t::get_assigns(), 0);
 }
 
+namespace ceph {
 // make sure that the legacy encode/decode methods are selected
 // over the ones defined using templates. the later is likely to
 // be slower, see also the definition of "WRITE_INT_DENC" in
@@ -263,6 +264,7 @@ void encode<ceph_le64, denc_traits<ceph_le64>>(const ceph_le64&,
   // make sure the test fails if i get called
   ASSERT_TRUE(false);
 }
+}
 
 namespace {
   // search `underlying_type` in denc.h for supported underlying types