From: Sage Weil Date: Wed, 14 Dec 2016 20:06:38 +0000 (-0500) Subject: include/denc: pass features through to decode() on featured objects X-Git-Tag: v11.1.1~54^2~3 X-Git-Url: http://git-server-git.apps.pok.os.sepia.ceph.com/?a=commitdiff_plain;h=2af1b029ca01ee0108a17414a7ff120095189104;p=ceph.git include/denc: pass features through to decode() on featured objects 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 --- diff --git a/src/include/denc.h b/src/include/denc.h index 4f310ea0b0cc..2f89dea2e8aa 100644 --- a/src/include/denc.h +++ b/src/include/denc.h @@ -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::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 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::type encode(const std::pair& 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& v, buffer::ptr::iterator& p) { - denc(v.first, p); - denc(v.second, p); + static void decode(std::pair& 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& s, buffer::ptr::iterator& p) { + static void decode(std::list& 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& s, buffer::ptr::iterator& p) { + static void decode(std::vector& 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& s, - buffer::ptr::iterator& p) { + buffer::ptr::iterator& p, uint64_t f=0) { s.resize(num); for (unsigned i=0; i& s, buffer::ptr::iterator& p) { + static void decode(std::set& 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& 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& v, buffer::ptr::iterator& p) { + static void decode(std::map& 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& 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 \ friend typename std::enable_if::value || \