]> git.apps.os.sepia.ceph.com Git - ceph.git/commitdiff
encoding: add optional features
authorSage Weil <sage@newdream.net>
Thu, 20 Oct 2011 04:45:59 +0000 (21:45 -0700)
committerSage Weil <sage@newdream.net>
Thu, 20 Oct 2011 04:45:59 +0000 (21:45 -0700)
Update encode macros to allow a feature bitmask to be passed through
to a classes encode() method.

Signed-off-by: Sage Weil <sage@newdream.net>
src/include/encoding.h

index adb329f9c0a9f16ffb754b94972bcd9d47cfcf4f..bbbac8f394398b3d1ce2d95b2f21214b23d68d8f 100644 (file)
@@ -23,6 +23,25 @@ using namespace ceph;
 
 #include <tr1/memory>
 
+/*
+ * Notes on feature encoding:
+ *
+ * - The default encode() methods have a features argument with a default parameter
+ *   (which goes to zero).
+ * - Normal classes will use WRITE_CLASS_ENCODER, with that features=0 default.
+ * - Classes that _require_ features will use WRITE_CLASS_ENCODER_FEATURES, which
+ *   does not define the default.  Any caller must explicitly pass it in.
+ * - STL container macros have two encode variants: one with a features arg, and one
+ *   without.
+ *
+ * The result:
+ * - A feature encode() method will fail to compile if a value is not
+ *   passed in.
+ * - The feature varianet of the STL templates will be used when the feature arg is
+ *   provided.  It will be passed through to any template arg types, but it will be
+ *   ignored when not needed.
+ */
+
 // --------------------------------------
 // base types
 
@@ -38,7 +57,7 @@ inline void decode_raw(T& t, bufferlist::iterator &p)
 }
 
 #define WRITE_RAW_ENCODER(type)                                                \
-  inline void encode(const type &v, bufferlist& bl) { encode_raw(v, bl); } \
+  inline void encode(const type &v, bufferlist& bl, uint64_t features=0) { encode_raw(v, bl); } \
   inline void decode(type &v, bufferlist::iterator& p) { decode_raw(v, p); }
 
 WRITE_RAW_ENCODER(__u8)
@@ -67,7 +86,7 @@ inline void decode(bool &v, bufferlist::iterator& p) {
 // int types
 
 #define WRITE_INTTYPE_ENCODER(type, etype)                             \
-  inline void encode(type v, bufferlist& bl) {                 \
+  inline void encode(type v, bufferlist& bl, uint64_t features=0) {    \
     __##etype e = init_##etype(v);                                     \
     encode_raw(e, bl);                                                 \
   }                                                                    \
@@ -87,13 +106,17 @@ WRITE_INTTYPE_ENCODER(int16_t, le16)
 
 
 #define WRITE_CLASS_ENCODER(cl) \
-  inline void encode(const cl &c, bufferlist &bl) { c.encode(bl); }    \
+  inline void encode(const cl &c, bufferlist &bl, uint64_t features=0) { c.encode(bl); } \
   inline void decode(cl &c, bufferlist::iterator &p) { c.decode(p); }
 
 #define WRITE_CLASS_MEMBER_ENCODER(cl) \
   inline void encode(const cl &c, bufferlist &bl) const { c.encode(bl); }      \
   inline void decode(cl &c, bufferlist::iterator &p) { c.decode(p); }
 
+#define WRITE_CLASS_ENCODER_FEATURES(cl)                               \
+  inline void encode(const cl &c, bufferlist &bl, uint64_t features) { c.encode(bl, features); } \
+  inline void decode(cl &c, bufferlist::iterator &p) { c.decode(p); }
+
 
 // string
 inline void encode(const std::string& s, bufferlist& bl) 
@@ -444,6 +467,16 @@ inline void encode(const std::map<T,U>& m, bufferlist& bl)
   }
 }
 template<class T, class U>
+inline void encode(const std::map<T,U>& m, bufferlist& bl, uint64_t features)
+{
+  __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, features);
+    encode(p->second, bl, features);
+  }
+}
+template<class T, class U>
 inline void decode(std::map<T,U>& m, bufferlist::iterator& p)
 {
   __u32 n;