From 8b2b83867ec049e3b8c0840d44286d38993779ee Mon Sep 17 00:00:00 2001 From: Kefu Chai Date: Tue, 27 Nov 2018 10:47:07 +0800 Subject: [PATCH] denc: add non-contiguous decode_nohead() for bl,string 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 --- src/include/denc.h | 12 ++++++++---- 1 file changed, 8 insertions(+), 4 deletions(-) diff --git a/src/include/denc.h b/src/include/denc.h index de74e41faad..d4733f09c84 100644 --- a/src/include/denc.h +++ b/src/include/denc.h @@ -728,15 +728,14 @@ public: s.append(p.get_pos_add(len), len); } } - template - static std::enable_if_t> - 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) { 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 { 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); + } }; // -- 2.39.5