From: Casey Bodley Date: Tue, 16 May 2017 19:46:02 +0000 (-0400) Subject: sstring: add denc() support X-Git-Tag: v12.1.0~256^2~2^2~1 X-Git-Url: http://git-server-git.apps.pok.os.sepia.ceph.com/?a=commitdiff_plain;h=3903c3b934c04e763cafd88aa70180bf58de4df0;p=ceph.git sstring: add denc() support Signed-off-by: Casey Bodley Signed-off-by: Kefu Chai --- diff --git a/src/common/sstring.hh b/src/common/sstring.hh index 8d2c92cc4de9..954c01d193fc 100644 --- a/src/common/sstring.hh +++ b/src/common/sstring.hh @@ -38,6 +38,9 @@ #include #include +#include "include/buffer.h" +#include "include/denc.h" + template class basic_sstring; @@ -647,6 +650,60 @@ inline string_type to_sstring(T value) { return sstring::to_sstring(value); } + +// encode/decode +template +struct denc_traits> { +private: + using value_type = basic_sstring; +public: + static constexpr bool supported = true; + static constexpr bool featured = false; + static constexpr bool bounded = false; + + static void bound_encode(const value_type& s, size_t& p, uint64_t f=0) { + p += sizeof(Size) + s.size(); + } + + static void encode_nohead(const value_type& s, + buffer::list::contiguous_appender& p) + { + auto len = s.size(); + if (len) { + p.append(reinterpret_cast(s.c_str()), len); + } + } + + static void decode_nohead(size_t len, value_type& s, + buffer::ptr::iterator& p) + { + s.reset(); + if (len) { + s.append(reinterpret_cast(p.get_pos_add(len)), len); + } + } + + static void encode(const value_type& s, + buffer::list::contiguous_appender& p, + uint64_t f=0) + { + Size len = (Size)(s.size()); + ::denc(len, p); + if (len) { + p.append(reinterpret_cast(s.c_str()), len); + } + } + + static void decode(value_type& s, + buffer::ptr::iterator& p, + uint64_t f=0) + { + Size len; + ::denc(len, p); + decode_nohead(len, s, p); + } +}; + #if 0 /* XXX conflicts w/Ceph types.h */ template inline