]> git.apps.os.sepia.ceph.com Git - ceph.git/commitdiff
include/denc: pass features through to decode() on featured objects
authorSage Weil <sage@redhat.com>
Wed, 14 Dec 2016 20:06:38 +0000 (15:06 -0500)
committerSage Weil <sage@redhat.com>
Wed, 14 Dec 2016 20:06:38 +0000 (15:06 -0500)
This allows featured objects the *option* to do something
meaningful with the features.  Generally the decoding is feature
independent, but in some cases decoding might be dependent on the
struct_v or features from a containing context and we need to
pass it through.

Signed-off-by: Sage Weil <sage@redhat.com>
src/include/denc.h

index 4f310ea0b0cc19c405af7d51c6458e112766ce0b..2f89dea2e8aa03b68b4abd60c27b0b1dde386467 100644 (file)
@@ -60,19 +60,18 @@ struct denc_traits {
     inline void denc(const T& o, size_t& p, uint64_t features=0);
     inline void denc(const T& o, buffer::list::contiguous_appender& p,
                      uint64_t features=0);
-    inline void denc(T& o, buffer::ptr::iterator& p);
+    inline void denc(T& o, buffer::ptr::iterator& p, uint64_t features=0);
 
   or (for featured objects)
 
     inline void denc(const T& o, size_t& p, uint64_t features);
     inline void denc(const T& o, buffer::list::contiguous_appender& p,
                      uint64_t features);
-    inline void denc(T& o, buffer::ptr::iterator& p);
+    inline void denc(T& o, buffer::ptr::iterator& p, uint64_t features);
 
   - These are symmetrical, so that they can be used from the magic DENC
   method of writing the bound_encode/encode/decode methods all in one go;
-  they differ only in the type of p.  The feature argument for decode is
-  ignored.
+  they differ only in the type of p.
 
   - These are automatically fabricated via a template that calls into
   the denc_traits<> methods (see below), provided denc_traits<T>::supported
@@ -90,7 +89,7 @@ struct denc_traits {
       static void bound_encode(const T &o, size_t& p, uint64_t f=0);
       static void encode(const T &o, buffer::list::contiguous_appender& p,
                         uint64_t f=0);
-      static void decode(T& o, buffer::ptr::iterator &p);
+      static void decode(T& o, buffer::ptr::iterator &p, uint64_t f=0);
     };
 
   or (for featured objects)
@@ -103,7 +102,7 @@ struct denc_traits {
       static void bound_encode(const T &o, size_t& p, uint64_t f);
       static void encode(const T &o, buffer::list::contiguous_appender& p,
                         uint64_t f);
-      static void decode(T& o, buffer::ptr::iterator &p);
+      static void decode(T& o, buffer::ptr::iterator &p, uint64_t f=0);
     };
 
   - denc_traits<T> is normally declared via the WRITE_CLASS_DENC(type) macro,
@@ -176,7 +175,8 @@ struct denc_traits {
                       uint64_t f=0) {                                  \
       p.append((const char*)&o, sizeof(o));                            \
     }                                                                  \
-    static void decode(type& o, buffer::ptr::iterator &p) {            \
+    static void decode(type& o, buffer::ptr::iterator &p,              \
+                      uint64_t f=0) {                                  \
       o = *(type *)p.get_pos_add(sizeof(o));                           \
     }                                                                  \
   };
@@ -214,8 +214,9 @@ WRITE_RAW_DENC(int8_t);
                       uint64_t f=0) {                                  \
       *(etype *)p.get_pos_add(sizeof(etype)) = o;                      \
     }                                                                  \
-    static void decode(itype& o, buffer::ptr::iterator &p) {           \
-      o = *(etype*)p.get_pos_add(sizeof(etype));                               \
+    static void decode(itype& o, buffer::ptr::iterator &p,             \
+                      uint64_t f=0) {                                  \
+      o = *(etype*)p.get_pos_add(sizeof(etype));                       \
     }                                                                  \
   };
 
@@ -502,7 +503,7 @@ inline typename std::enable_if<traits::supported != 0 &&
   buffer::ptr::iterator& p,
   uint64_t features=0)
 {
-  traits::decode(o, p);
+  traits::decode(o, p, features);
 }
 
 
@@ -623,14 +624,14 @@ struct denc_traits<
   static typename std::enable_if<sizeof(AA) &&
                                 featured, void>::type
   encode(const std::pair<A,B>& v, bufferlist::contiguous_appender& p,
-          uint64_t f) {
+        uint64_t f) {
     denc(v.first, p, f);
     denc(v.second, p, f);
   }
 
-  static void decode(std::pair<A,B>& v, buffer::ptr::iterator& p) {
-    denc(v.first, p);
-    denc(v.second, p);
+  static void decode(std::pair<A,B>& v, buffer::ptr::iterator& p, uint64_t f=0) {
+    denc(v.first, p, f);
+    denc(v.second, p, f);
   }
 };
 
@@ -705,13 +706,14 @@ struct denc_traits<
       denc(e, p, f);
     }
   }
-  static void decode(std::list<T>& s, buffer::ptr::iterator& p) {
+  static void decode(std::list<T>& s, buffer::ptr::iterator& p,
+                    uint64_t f=0) {
     s.clear();
     uint32_t num;
     denc(num, p);
     while (num--) {
       s.emplace_back(T());
-      denc(s.back(), p);
+      denc(s.back(), p, f);
     }
   }
 };
@@ -787,13 +789,13 @@ struct denc_traits<
       denc(e, p, f);
     }
   }
-  static void decode(std::vector<T>& s, buffer::ptr::iterator& p) {
+  static void decode(std::vector<T>& s, buffer::ptr::iterator& p, uint64_t f=0) {
     s.clear();
     uint32_t num;
     denc(num, p);
     s.resize(num);
     for (unsigned i=0; i<num; ++i) {
-      denc(s[i], p);
+      denc(s[i], p, f);
     }
   }
 
@@ -816,10 +818,10 @@ struct denc_traits<
     }
   }
   static void decode_nohead(size_t num, std::vector<T>& s,
-                           buffer::ptr::iterator& p) {
+                           buffer::ptr::iterator& p, uint64_t f=0) {
     s.resize(num);
     for (unsigned i=0; i<num; ++i) {
-      denc(s[i], p);
+      denc(s[i], p, f);
     }
   }
 
@@ -896,13 +898,13 @@ struct denc_traits<
       denc(e, p, f);
     }
   }
-  static void decode(std::set<T>& s, buffer::ptr::iterator& p) {
+  static void decode(std::set<T>& s, buffer::ptr::iterator& p, uint64_t f=0) {
     s.clear();
     uint32_t num;
     denc(num, p);
     while (num--) {
       T temp;
-      denc(temp, p);
+      denc(temp, p, f);
       s.insert(temp);
     }
   }
@@ -926,11 +928,11 @@ struct denc_traits<
     }
   }
   static void decode_nohead(size_t num, std::set<T>& s,
-                           buffer::ptr::iterator& p) {
+                           buffer::ptr::iterator& p, uint64_t f=0) {
     s.clear();
     while (num--) {
       T temp;
-      denc(temp, p);
+      denc(temp, p, f);
       s.insert(temp);
     }
   }
@@ -1019,14 +1021,14 @@ struct denc_traits<
     }
   }
 
-  static void decode(std::map<A,B>& v, buffer::ptr::iterator& p) {
+  static void decode(std::map<A,B>& v, buffer::ptr::iterator& p, uint64_t f=0) {
     v.clear();
     uint32_t num;
     denc(num, p);
     A key;
     while (num--) {
-      denc(key, p);
-      denc(v[key], p);
+      denc(key, p, f);
+      denc(v[key], p, f);
     }
   }
 
@@ -1051,12 +1053,13 @@ struct denc_traits<
     }
   }
   static void decode_nohead(size_t num, std::map<A,B>& v,
-                           buffer::ptr::iterator& p) {
+                           buffer::ptr::iterator& p,
+                           uint64_t f=0) {
     v.clear();
     A key;
     while (num--) {
-      denc(key, p);
-      denc(v[key], p);
+      denc(key, p, f);
+      denc(v[key], p, f);
     }
   }
 };
@@ -1082,7 +1085,7 @@ struct denc_traits<
                       uint64_t f=0) {                                  \
       v.encode(p);                                                     \
     }                                                                  \
-    static void decode(T& v, buffer::ptr::iterator& p) {               \
+    static void decode(T& v, buffer::ptr::iterator& p, uint64_t f=0) { \
       v.decode(p);                                                     \
     }                                                                  \
   };
@@ -1101,8 +1104,8 @@ struct denc_traits<
                       uint64_t f) {                                    \
       v.encode(p, f);                                                  \
     }                                                                  \
-    static void decode(T& v, buffer::ptr::iterator& p) {               \
-      v.decode(p);                                                     \
+    static void decode(T& v, buffer::ptr::iterator& p, uint64_t f=0) { \
+      v.decode(p, f);                                                  \
     }                                                                  \
   };
 
@@ -1314,8 +1317,8 @@ inline typename std::enable_if<traits::supported == 1 &&
   void encode(bufferlist::contiguous_appender& p, uint64_t f) const {  \
     _denc_friend(*this, p, f);                                         \
   }                                                                    \
-  void decode(buffer::ptr::iterator& p) {                              \
-    _denc_friend(*this, p, 0);                                         \
+  void decode(buffer::ptr::iterator& p, uint64_t f=0) {                        \
+    _denc_friend(*this, p, f);                                         \
   }                                                                    \
   template<typename T, typename P>                                     \
   friend typename std::enable_if<boost::is_same<T,Type>::value ||      \