From: Kefu Chai Date: Mon, 26 Nov 2018 15:52:39 +0000 (+0800) Subject: denc: enable decode basic_string<> X-Git-Tag: v14.1.0~772^2~5 X-Git-Url: http://git.apps.os.sepia.ceph.com/?a=commitdiff_plain;h=c4544d1514b49b7b434d79e7490af8564fb1b1ea;p=ceph-ci.git denc: enable decode basic_string<> we have buffer::list::iterator_impl::copy(unsigned len, std::string &dest) but we don't have the templatized version of it. so, if we plugin a different allocator to basic_string<>, the new string won't decode with buffer::list::const_iterator. this decode variant is used if the caller only has a (probably non-contiguous) buffer::list in hand. in this change, copy(unsigned, char*) is used as an alternative. Signed-off-by: Kefu Chai --- diff --git a/src/include/denc.h b/src/include/denc.h index 2e562598903..d56bf93d861 100644 --- a/src/include/denc.h +++ b/src/include/denc.h @@ -714,17 +714,36 @@ public: uint32_t len; denc(len, p); s.clear(); - p.copy(len, s); + if constexpr (std::is_same_v) { + p.copy(len, s); + } else { + s.append(len, 0); + p.copy(len, s.data()); + } } 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, It& p) { s.clear(); if (len) { s.append(p.get_pos_add(len), len); } } template + static std::enable_if_t> + decode_nohead(size_t len, value_type& s, It& p) { + if (len) { + if constexpr (std::is_same_v) { + s.clear(); + p.copy(len, s); + } else { + s.resize(len, 0); + p.copy(len, s.data()); + } + } else { + s.clear(); + } + } + template static std::enable_if_t> encode_nohead(const value_type& s, It& p) { auto len = s.length();