summaryrefslogtreecommitdiffstats
path: root/src/common
diff options
context:
space:
mode:
authorSage Weil <sage@newdream.net>2017-05-31 17:38:53 +0200
committerGitHub <noreply@github.com>2017-05-31 17:38:53 +0200
commit0a8beea82eb6b2a9de02cfa374bc9afc240f079e (patch)
tree59363c690ca7a38dfae0f99c1f59777aea7d4546 /src/common
parentMerge pull request #13802 from LiumxNL/wip-170306 (diff)
parenttest: add denc tests for sstring (diff)
downloadceph-0a8beea82eb6b2a9de02cfa374bc9afc240f079e.tar.xz
ceph-0a8beea82eb6b2a9de02cfa374bc9afc240f079e.zip
Merge pull request #15135 from cbodley/wip-denc-sstring
denc: add encode/decode for basic_sstring Reviewed-by: Sage Weil <sage@redhat.com>
Diffstat (limited to 'src/common')
-rw-r--r--src/common/sstring.hh57
1 files changed, 57 insertions, 0 deletions
diff --git a/src/common/sstring.hh b/src/common/sstring.hh
index 6e60b52fe0f..4b75e097681 100644
--- a/src/common/sstring.hh
+++ b/src/common/sstring.hh
@@ -29,6 +29,9 @@
#include <type_traits>
#include <boost/utility/string_ref.hpp>
+#include "include/buffer.h"
+#include "include/denc.h"
+
template <typename char_type, typename Size, Size max_size>
class basic_sstring;
@@ -638,6 +641,60 @@ inline string_type to_sstring(T value) {
return sstring::to_sstring<string_type>(value);
}
+
+// encode/decode
+template <typename Char, typename Size, Size Max>
+struct denc_traits<basic_sstring<Char, Size, Max>> {
+private:
+ using value_type = basic_sstring<Char, Size, Max>;
+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<const char*>(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<const Char*>(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<const char*>(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 <typename T>
inline