]> git.apps.os.sepia.ceph.com Git - ceph-ci.git/commitdiff
denc: add non-contiguous decode_nohead() for bl,string
authorKefu Chai <kchai@redhat.com>
Tue, 27 Nov 2018 02:47:07 +0000 (10:47 +0800)
committerKefu Chai <kchai@redhat.com>
Tue, 27 Nov 2018 16:33:51 +0000 (00:33 +0800)
bufferlist's denc traits claims to be need_contiguous=false, so
it should implement all all functions to work with
buffer::list::const_iterator. we already have decode(), the missing
puzzle is decode_nohead().

in this change, decode_nohead(size_t len, bufferlist& v,
                              buffer::list::const_iterator& p) is implemented.

same applies to basic_string.

ideally, we should allow decode buffer::list::iterator as well. but
let's leave it for another change in future when it's needed.

Signed-off-by: Kefu Chai <kchai@redhat.com>
src/include/denc.h

index de74e41faad789ae290b5c2aa110783bf5e17cb3..d4733f09c8499cdbabf62531cf959a0bedb1369c 100644 (file)
@@ -728,15 +728,14 @@ public:
       s.append(p.get_pos_add(len), len);
     }
   }
-  template<class It>
-  static std::enable_if_t<is_const_iterator_v<It>>
-  decode_nohead(size_t len, value_type& s, It& p) {
+  static void decode_nohead(size_t len, value_type& s,
+                            buffer::list::const_iterator& p) {
     if (len) {
       if constexpr (std::is_same_v<value_type, std::string>) {
         s.clear();
         p.copy(len, s);
       } else {
-        s.resize(len, 0);
+        s.resize(len);
         p.copy(len, s.data());
       }
     } else {
@@ -830,6 +829,11 @@ struct denc_traits<bufferlist> {
       v.append(p.get_ptr(len));
     }
   }
+  static void decode_nohead(size_t len, bufferlist& v,
+                           buffer::list::const_iterator& p) {
+    v.clear();
+    p.copy(len, v);
+  }
 };
 
 //