From 7b961ff1295c95f549103a442018b896eb45374a Mon Sep 17 00:00:00 2001 From: Sage Weil Date: Wed, 30 Dec 2015 15:04:28 -0500 Subject: [PATCH] include/encoding: featureful encoder for list of shared_ptrs Signed-off-by: Sage Weil --- src/include/encoding.h | 22 ++++++++++++++++++++++ 1 file changed, 22 insertions(+) diff --git a/src/include/encoding.h b/src/include/encoding.h index a5a93a0996b7c..7de74544b2cc4 100644 --- a/src/include/encoding.h +++ b/src/include/encoding.h @@ -423,6 +423,28 @@ inline void encode(const std::list >& ls, bufferlist& bl) } } template +inline void encode(const std::list >& ls, bufferlist& bl, uint64_t features) +{ + // 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, features); + } + ceph_le32 en; + en = n; + bl.copy_in(pos, sizeof(en), (char*)&en); + } else { + __u32 n = (__u32)(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, features); + } +} +template inline void decode(std::list >& ls, bufferlist::iterator& p) { __u32 n; -- 2.39.5