From f78de01ab6702ab13af059b3c8dde4008761fe54 Mon Sep 17 00:00:00 2001 From: Sage Weil Date: Mon, 20 Jun 2011 13:54:41 -0700 Subject: [PATCH] encoding: add list> macros Signed-off-by: Sage Weil --- src/include/encoding.h | 37 +++++++++++++++++++++++++++++++++++++ 1 file changed, 37 insertions(+) diff --git a/src/include/encoding.h b/src/include/encoding.h index 8ab5fe90f37e7..f9e35145391e7 100644 --- a/src/include/encoding.h +++ b/src/include/encoding.h @@ -21,6 +21,8 @@ using namespace ceph; +#include + // -------------------------------------- // base types @@ -296,6 +298,41 @@ inline void decode(std::list& ls, bufferlist::iterator& p) } } +template +inline void encode(const std::list >& ls, bufferlist& bl) +{ + // should i pre- or post- count? + if (!ls.empty()) { + unsigned pos = bl.length(); + unsigned n = 0; + encode(n, bl); + for (typename std::list >::const_iterator p = ls.begin(); p != ls.end(); ++p) { + n++; + encode(**p, bl); + } + __le32 en; + en = n; + bl.copy_in(pos, sizeof(en), (char*)&en); + } else { + __u32 n = ls.size(); // FIXME: this is slow on a list. + encode(n, bl); + for (typename std::list >::const_iterator p = ls.begin(); p != ls.end(); ++p) + encode(**p, bl); + } +} +template +inline void decode(std::list >& ls, bufferlist::iterator& p) +{ + __u32 n; + decode(n, p); + ls.clear(); + while (n--) { + std::tr1::shared_ptr v(new T); + decode(*v, p); + ls.push_back(v); + } +} + // set template inline void encode(const std::set& s, bufferlist& bl) -- 2.39.5