]> git.apps.os.sepia.ceph.com Git - ceph.git/commitdiff
include/encoding: featureful encoder for list of shared_ptrs
authorSage Weil <sage@redhat.com>
Wed, 30 Dec 2015 20:04:28 +0000 (15:04 -0500)
committerSage Weil <sage@redhat.com>
Tue, 1 Mar 2016 16:16:59 +0000 (11:16 -0500)
Signed-off-by: Sage Weil <sage@redhat.com>
src/include/encoding.h

index a5a93a0996b7cbe8dca845999ca4266ceef9e8ed..7de74544b2cc45422bee052a42f9e767a7243e14 100644 (file)
@@ -423,6 +423,28 @@ inline void encode(const std::list<ceph::shared_ptr<T> >& ls, bufferlist& bl)
   }
 }
 template<class T>
+inline void encode(const std::list<ceph::shared_ptr<T> >& ls, bufferlist& bl, uint64_t features)
+{
+  // should i pre- or post- count?
+  if (!ls.empty()) {
+    unsigned pos = bl.length();
+    unsigned n = 0;
+    encode(n, bl);
+    for (typename std::list<ceph::shared_ptr<T> >::const_iterator p = ls.begin(); p != ls.end(); ++p) {
+      n++;
+      encode(**p, bl, features);
+    }
+    ceph_le32 en;
+    en = n;
+    bl.copy_in(pos, sizeof(en), (char*)&en);
+  } else {
+    __u32 n = (__u32)(ls.size());    // FIXME: this is slow on a list.
+    encode(n, bl);
+    for (typename std::list<ceph::shared_ptr<T> >::const_iterator p = ls.begin(); p != ls.end(); ++p)
+      encode(**p, bl, features);
+  }
+}
+template<class T>
 inline void decode(std::list<ceph::shared_ptr<T> >& ls, bufferlist::iterator& p)
 {
   __u32 n;