#ifndef CEPH_ENCODING_H
#define CEPH_ENCODING_H
+#include <set>
+#include <map>
+#include <deque>
+#include <vector>
+#include <string>
+#include <boost/optional/optional_io.hpp>
+#include <boost/tuple/tuple.hpp>
+
+#ifndef _BACKWARD_BACKWARD_WARNING_H
+#define _BACKWARD_BACKWARD_WARNING_H // make gcc 4.3 shut up about hash_*
+#endif
+#include "include/unordered_map.h"
+#include "include/unordered_set.h"
+
+
+
#include "include/int_types.h"
#include "include/memory.h"
using namespace ceph;
+namespace ceph {
+
/*
* Notes on feature encoding:
*
}
#define WRITE_RAW_ENCODER(type) \
- inline void encode(const type &v, bufferlist& bl, uint64_t features=0) { encode_raw(v, bl); } \
- inline void decode(type &v, bufferlist::iterator& p) { __ASSERT_FUNCTION decode_raw(v, p); }
+ inline void encode(const type &v, ::ceph::bufferlist& bl, uint64_t features=0) { ::ceph::encode_raw(v, bl); } \
+ inline void decode(type &v, ::ceph::bufferlist::iterator& p) { __ASSERT_FUNCTION ::ceph::decode_raw(v, p); }
WRITE_RAW_ENCODER(__u8)
#ifndef _CHAR_IS_SIGNED
// int types
#define WRITE_INTTYPE_ENCODER(type, etype) \
- inline void encode(type v, bufferlist& bl, uint64_t features=0) { \
+ inline void encode(type v, ::ceph::bufferlist& bl, uint64_t features=0) { \
ceph_##etype e; \
e = v; \
- encode_raw(e, bl); \
+ ::ceph::encode_raw(e, bl); \
} \
- inline void decode(type &v, bufferlist::iterator& p) { \
+ inline void decode(type &v, ::ceph::bufferlist::iterator& p) { \
ceph_##etype e; \
- decode_raw(e, p); \
+ ::ceph::decode_raw(e, p); \
v = e; \
}
snprintf(fn, sizeof(fn), ENCODE_STRINGIFY(ENCODE_DUMP_PATH) "/%s__%d.%x", #cl, getpid(), i++); \
int fd = ::open(fn, O_WRONLY|O_TRUNC|O_CREAT, 0644); \
if (fd >= 0) { \
- bufferlist sub; \
+ ::ceph::bufferlist sub; \
sub.substr_of(bl, pre_off, bl.length() - pre_off); \
sub.write_fd(fd); \
::close(fd); \
#define WRITE_CLASS_ENCODER(cl) \
- inline void encode(const cl &c, bufferlist &bl, uint64_t features=0) { \
+ inline void encode(const cl &c, ::ceph::bufferlist &bl, uint64_t features=0) { \
ENCODE_DUMP_PRE(); c.encode(bl); ENCODE_DUMP_POST(cl); } \
- inline void decode(cl &c, bufferlist::iterator &p) { c.decode(p); }
+ inline void decode(cl &c, ::ceph::bufferlist::iterator &p) { c.decode(p); }
#define WRITE_CLASS_MEMBER_ENCODER(cl) \
- inline void encode(const cl &c, bufferlist &bl) const { \
+ inline void encode(const cl &c, ::ceph::bufferlist &bl) const { \
ENCODE_DUMP_PRE(); c.encode(bl); ENCODE_DUMP_POST(cl); } \
- inline void decode(cl &c, bufferlist::iterator &p) { c.decode(p); }
+ inline void decode(cl &c, ::ceph::bufferlist::iterator &p) { c.decode(p); }
#define WRITE_CLASS_ENCODER_FEATURES(cl) \
- inline void encode(const cl &c, bufferlist &bl, uint64_t features) { \
+ inline void encode(const cl &c, ::ceph::bufferlist &bl, uint64_t features) { \
ENCODE_DUMP_PRE(); c.encode(bl, features); ENCODE_DUMP_POST(cl); } \
- inline void decode(cl &c, bufferlist::iterator &p) { c.decode(p); }
+ inline void decode(cl &c, ::ceph::bufferlist::iterator &p) { c.decode(p); }
#define WRITE_CLASS_ENCODER_OPTIONAL_FEATURES(cl) \
- inline void encode(const cl &c, bufferlist &bl, uint64_t features = 0) { \
+ inline void encode(const cl &c, ::ceph::bufferlist &bl, uint64_t features = 0) { \
ENCODE_DUMP_PRE(); c.encode(bl, features); ENCODE_DUMP_POST(cl); } \
- inline void decode(cl &c, bufferlist::iterator &p) { c.decode(p); }
+ inline void decode(cl &c, ::ceph::bufferlist::iterator &p) { c.decode(p); }
// string
// -----------------------------
// STL container types
-#include <set>
-#include <map>
-#include <deque>
-#include <vector>
-#include <string>
-#include <boost/optional/optional_io.hpp>
-#include <boost/tuple/tuple.hpp>
-
-#ifndef _BACKWARD_BACKWARD_WARNING_H
-#define _BACKWARD_BACKWARD_WARNING_H // make gcc 4.3 shut up about hash_*
-#endif
-#include "include/unordered_map.h"
-#include "include/unordered_set.h"
+template<typename T>
+inline void encode(const boost::optional<T> &p, bufferlist &bl);
+template<typename T>
+inline void decode(boost::optional<T> &p, bufferlist::iterator &bp);
+template<class A, class B, class C>
+inline void encode(const boost::tuple<A, B, C> &t, bufferlist& bl);
+template<class A, class B, class C>
+inline void decode(boost::tuple<A, B, C> &t, bufferlist::iterator &bp);
+template<class A, class B,
+ typename a_traits=denc_traits<A>, typename b_traits=denc_traits<B>>
+inline std::enable_if_t<!a_traits::supported || !b_traits::supported>
+encode(const std::pair<A,B> &p, bufferlist &bl, uint64_t features);
+template<class A, class B,
+ typename a_traits=denc_traits<A>, typename b_traits=denc_traits<B>>
+inline std::enable_if_t<!a_traits::supported ||
+ !b_traits::supported>
+encode(const std::pair<A,B> &p, bufferlist &bl);
+template<class A, class B,
+ typename a_traits=denc_traits<A>, typename b_traits=denc_traits<B>>
+inline std::enable_if_t<!a_traits::supported ||
+ !b_traits::supported>
+decode(std::pair<A,B> &pa, bufferlist::iterator &p);
+template<class T, class Alloc, typename traits=denc_traits<T>>
+inline std::enable_if_t<!traits::supported>
+encode(const std::list<T, Alloc>& ls, bufferlist& bl);
+template<class T, class Alloc, typename traits=denc_traits<T>>
+inline std::enable_if_t<!traits::supported>
+encode(const std::list<T,Alloc>& ls, bufferlist& bl, uint64_t features);
+template<class T, class Alloc, typename traits=denc_traits<T>>
+inline std::enable_if_t<!traits::supported>
+decode(std::list<T,Alloc>& ls, bufferlist::iterator& p);
+template<class T, class Alloc>
+inline void encode(const std::list<ceph::shared_ptr<T>, Alloc>& ls,
+ bufferlist& bl);
+template<class T, class Alloc>
+inline void encode(const std::list<ceph::shared_ptr<T>, Alloc>& ls,
+ bufferlist& bl, uint64_t features);
+template<class T, class Alloc>
+inline void decode(std::list<ceph::shared_ptr<T>, Alloc>& ls,
+ bufferlist::iterator& p);
+template<class T, class Comp, class Alloc, typename traits=denc_traits<T>>
+inline std::enable_if_t<!traits::supported>
+encode(const std::set<T,Comp,Alloc>& s, bufferlist& bl);
+template<class T, class Comp, class Alloc, typename traits=denc_traits<T>>
+inline std::enable_if_t<!traits::supported>
+decode(std::set<T,Comp,Alloc>& s, bufferlist::iterator& p);
+template<class T, class Comp, class Alloc, typename traits=denc_traits<T>>
+inline std::enable_if_t<!traits::supported>
+encode_nohead(const std::set<T,Comp,Alloc>& s, bufferlist& bl);
+template<class T, class Comp, class Alloc, typename traits=denc_traits<T>>
+inline std::enable_if_t<!traits::supported>
+decode_nohead(int len, std::set<T,Comp,Alloc>& s, bufferlist::iterator& p);
+template<class T, class Comp, class Alloc, typename traits=denc_traits<T>>
+inline std::enable_if_t<!traits::supported>
+encode(const boost::container::flat_set<T, Comp, Alloc>& s, bufferlist& bl);
+template<class T, class Comp, class Alloc, typename traits=denc_traits<T>>
+inline std::enable_if_t<!traits::supported>
+decode(boost::container::flat_set<T, Comp, Alloc>& s, bufferlist::iterator& p);
+template<class T, class Comp, class Alloc, typename traits=denc_traits<T>>
+inline std::enable_if_t<!traits::supported>
+encode_nohead(const boost::container::flat_set<T, Comp, Alloc>& s,
+ bufferlist& bl);
+template<class T, class Comp, class Alloc, typename traits=denc_traits<T>>
+inline std::enable_if_t<!traits::supported>
+decode_nohead(int len, boost::container::flat_set<T, Comp, Alloc>& s,
+ bufferlist::iterator& p);
+template<class T, class Comp, class Alloc>
+inline void encode(const std::multiset<T,Comp,Alloc>& s, bufferlist& bl);
+template<class T, class Comp, class Alloc>
+inline void decode(std::multiset<T,Comp,Alloc>& s, bufferlist::iterator& p);
+template<class T, class Alloc, typename traits=denc_traits<T>>
+inline std::enable_if_t<!traits::supported>
+encode(const std::vector<T,Alloc>& v, bufferlist& bl, uint64_t features);
+template<class T, class Alloc, typename traits=denc_traits<T>>
+inline std::enable_if_t<!traits::supported>
+encode(const std::vector<T,Alloc>& v, bufferlist& bl);
+template<class T, class Alloc, typename traits=denc_traits<T>>
+inline std::enable_if_t<!traits::supported>
+decode(std::vector<T,Alloc>& v, bufferlist::iterator& p);
+template<class T, class Alloc, typename traits=denc_traits<T>>
+inline std::enable_if_t<!traits::supported>
+encode_nohead(const std::vector<T,Alloc>& v, bufferlist& bl);
+template<class T, class Alloc, typename traits=denc_traits<T>>
+inline std::enable_if_t<!traits::supported>
+decode_nohead(int len, std::vector<T,Alloc>& v, bufferlist::iterator& p);
+template<class T,class Alloc>
+inline void encode(const std::vector<ceph::shared_ptr<T>,Alloc>& v,
+ bufferlist& bl,
+ uint64_t features);
+template<class T, class Alloc>
+inline void encode(const std::vector<ceph::shared_ptr<T>,Alloc>& v,
+ bufferlist& bl);
+template<class T, class Alloc>
+inline void decode(std::vector<ceph::shared_ptr<T>,Alloc>& v,
+ bufferlist::iterator& p);
+template<class T, class U, class Comp, class Alloc,
+ typename t_traits=denc_traits<T>, typename u_traits=denc_traits<U>>
+inline std::enable_if_t<!t_traits::supported ||
+ !u_traits::supported>
+encode(const std::map<T,U,Comp,Alloc>& m, bufferlist& bl);
+template<class T, class U, class Comp, class Alloc,
+ typename t_traits=denc_traits<T>, typename u_traits=denc_traits<U>>
+inline std::enable_if_t<!t_traits::supported || !u_traits::supported>
+encode(const std::map<T,U,Comp,Alloc>& m, bufferlist& bl, uint64_t features);
+template<class T, class U, class Comp, class Alloc,
+ typename t_traits=denc_traits<T>, typename u_traits=denc_traits<U>>
+inline std::enable_if_t<!t_traits::supported || !u_traits::supported>
+decode(std::map<T,U,Comp,Alloc>& m, bufferlist::iterator& p);
+template<class T, class U, class Comp, class Alloc>
+inline void decode_noclear(std::map<T,U,Comp,Alloc>& m, bufferlist::iterator& p);
+template<class T, class U, class Comp, class Alloc,
+ typename t_traits=denc_traits<T>, typename u_traits=denc_traits<U>>
+inline std::enable_if_t<!t_traits::supported || !u_traits::supported>
+encode_nohead(const std::map<T,U,Comp,Alloc>& m, bufferlist& bl);
+template<class T, class U, class Comp, class Alloc,
+ typename t_traits=denc_traits<T>, typename u_traits=denc_traits<U>>
+inline std::enable_if_t<!t_traits::supported || !u_traits::supported>
+encode_nohead(const std::map<T,U,Comp,Alloc>& m, bufferlist& bl, uint64_t features);
+template<class T, class U, class Comp, class Alloc,
+ typename t_traits=denc_traits<T>, typename u_traits=denc_traits<U>>
+inline std::enable_if_t<!t_traits::supported || !u_traits::supported>
+decode_nohead(int n, std::map<T,U,Comp,Alloc>& m, bufferlist::iterator& p);
+template<class T, class U, class Comp, class Alloc,
+ typename t_traits=denc_traits<T>, typename u_traits=denc_traits<U>>
+ inline std::enable_if_t<!t_traits::supported || !u_traits::supported>
+encode(const boost::container::flat_map<T,U,Comp,Alloc>& m, bufferlist& bl);
+template<class T, class U, class Comp, class Alloc,
+ typename t_traits=denc_traits<T>, typename u_traits=denc_traits<U>>
+inline std::enable_if_t<!t_traits::supported || !u_traits::supported>
+encode(const boost::container::flat_map<T,U,Comp,Alloc>& m, bufferlist& bl,
+ uint64_t features);
+template<class T, class U, class Comp, class Alloc,
+ typename t_traits=denc_traits<T>, typename u_traits=denc_traits<U>>
+inline std::enable_if_t<!t_traits::supported || !u_traits::supported>
+decode(boost::container::flat_map<T,U,Comp,Alloc>& m, bufferlist::iterator& p);
+template<class T, class U, class Comp, class Alloc>
+inline void decode_noclear(boost::container::flat_map<T,U,Comp,Alloc>& m,
+ bufferlist::iterator& p);
+template<class T, class U, class Comp, class Alloc,
+ typename t_traits=denc_traits<T>, typename u_traits=denc_traits<U>>
+inline std::enable_if_t<!t_traits::supported || !u_traits::supported>
+encode_nohead(const boost::container::flat_map<T,U,Comp,Alloc>& m,
+ bufferlist& bl);
+template<class T, class U, class Comp, class Alloc,
+ typename t_traits=denc_traits<T>, typename u_traits=denc_traits<U>>
+inline std::enable_if_t<!t_traits::supported || !u_traits::supported>
+encode_nohead(const boost::container::flat_map<T,U,Comp,Alloc>& m,
+ bufferlist& bl, uint64_t features);
+template<class T, class U, class Comp, class Alloc,
+ typename t_traits=denc_traits<T>, typename u_traits=denc_traits<U>>
+inline std::enable_if_t<!t_traits::supported || !u_traits::supported>
+decode_nohead(int n, boost::container::flat_map<T,U,Comp,Alloc>& m,
+ bufferlist::iterator& p);
+template<class T, class U, class Comp, class Alloc>
+inline void encode(const std::multimap<T,U,Comp,Alloc>& m, bufferlist& bl);
+template<class T, class U, class Comp, class Alloc>
+inline void decode(std::multimap<T,U,Comp,Alloc>& m, bufferlist::iterator& p);
+template<class T, class U, class Hash, class Pred, class Alloc>
+inline void encode(const unordered_map<T,U,Hash,Pred,Alloc>& m, bufferlist& bl,
+ uint64_t features);
+template<class T, class U, class Hash, class Pred, class Alloc>
+inline void encode(const unordered_map<T,U,Hash,Pred,Alloc>& m, bufferlist& bl);
+template<class T, class U, class Hash, class Pred, class Alloc>
+inline void decode(unordered_map<T,U,Hash,Pred,Alloc>& m, bufferlist::iterator& p);
+template<class T, class Hash, class Pred, class Alloc>
+inline void encode(const ceph::unordered_set<T,Hash,Pred,Alloc>& m, bufferlist& bl);
+template<class T, class Hash, class Pred, class Alloc>
+inline void decode(ceph::unordered_set<T,Hash,Pred,Alloc>& m, bufferlist::iterator& p);
+template<class T, class Alloc>
+inline void encode(const std::deque<T,Alloc>& ls, bufferlist& bl, uint64_t features);
+template<class T, class Alloc>
+inline void encode(const std::deque<T,Alloc>& ls, bufferlist& bl);
+template<class T, class Alloc>
+inline void decode(std::deque<T,Alloc>& ls, bufferlist::iterator& p);
+template<class T, size_t N, typename traits = denc_traits<T>>
+inline std::enable_if_t<!traits::supported>
+encode(const std::array<T, N>& v, bufferlist& bl, uint64_t features);
+template<class T, size_t N, typename traits = denc_traits<T>>
+inline std::enable_if_t<!traits::supported>
+encode(const std::array<T, N>& v, bufferlist& bl);
+template<class T, size_t N, typename traits = denc_traits<T>>
+inline std::enable_if_t<!traits::supported>
+decode(std::array<T, N>& v, bufferlist::iterator& p);
// boost optional
inline void encode(const boost::optional<T> &p, bufferlist &bl)
{
__u8 present = static_cast<bool>(p);
- ::encode(present, bl);
+ encode(present, bl);
if (p)
encode(p.get(), bl);
}
inline void decode(boost::optional<T> &p, bufferlist::iterator &bp)
{
__u8 present;
- ::decode(present, bp);
+ decode(present, bp);
if (present) {
p = T{};
decode(p.get(), bp);
// std::pair<A,B>
template<class A, class B,
- typename a_traits=denc_traits<A>, typename b_traits=denc_traits<B>>
-inline typename std::enable_if<!a_traits::supported ||
- !b_traits::supported>::type
+ typename a_traits, typename b_traits>
+inline std::enable_if_t<!a_traits::supported || !b_traits::supported>
encode(const std::pair<A,B> &p, bufferlist &bl, uint64_t features)
{
encode(p.first, bl, features);
encode(p.second, bl, features);
}
template<class A, class B,
- typename a_traits=denc_traits<A>, typename b_traits=denc_traits<B>>
-inline typename std::enable_if<!a_traits::supported ||
- !b_traits::supported>::type
+ typename a_traits, typename b_traits>
+inline std::enable_if_t<!a_traits::supported ||
+ !b_traits::supported>
encode(const std::pair<A,B> &p, bufferlist &bl)
{
encode(p.first, bl);
encode(p.second, bl);
}
-template<class A, class B,
- typename a_traits=denc_traits<A>, typename b_traits=denc_traits<B>>
-inline typename std::enable_if<!a_traits::supported ||
- !b_traits::supported>::type
+template<class A, class B, typename a_traits, typename b_traits>
+inline std::enable_if_t<!a_traits::supported ||
+ !b_traits::supported>
decode(std::pair<A,B> &pa, bufferlist::iterator &p)
{
decode(pa.first, p);
}
// std::list<T>
-template<class T, class Alloc, typename traits=denc_traits<T>>
-inline typename std::enable_if<!traits::supported>::type
+template<class T, class Alloc, typename traits>
+inline std::enable_if_t<!traits::supported>
encode(const std::list<T, Alloc>& ls, bufferlist& bl)
{
__u32 n = (__u32)(ls.size()); // c++11 std::list::size() is O(1)
for (auto p = ls.begin(); p != ls.end(); ++p)
encode(*p, bl);
}
-template<class T, class Alloc, typename traits=denc_traits<T>>
-inline typename std::enable_if<!traits::supported>::type
+template<class T, class Alloc, typename traits>
+inline std::enable_if_t<!traits::supported>
encode(const std::list<T,Alloc>& ls, bufferlist& bl, uint64_t features)
{
// should i pre- or post- count?
encode(*p, bl, features);
}
}
-template<class T, class Alloc, typename traits=denc_traits<T>>
-inline typename std::enable_if<!traits::supported>::type
+template<class T, class Alloc, typename traits>
+inline std::enable_if_t<!traits::supported>
decode(std::list<T,Alloc>& ls, bufferlist::iterator& p)
{
__u32 n;
}
// std::set<T>
-template<class T, class Comp, class Alloc, typename traits=denc_traits<T>>
-inline typename std::enable_if<!traits::supported>::type
+template<class T, class Comp, class Alloc, typename traits>
+inline std::enable_if_t<!traits::supported>
encode(const std::set<T,Comp,Alloc>& s, bufferlist& bl)
{
__u32 n = (__u32)(s.size());
for (auto p = s.begin(); p != s.end(); ++p)
encode(*p, bl);
}
-template<class T, class Comp, class Alloc, typename traits=denc_traits<T>>
-inline typename std::enable_if<!traits::supported>::type
+template<class T, class Comp, class Alloc, typename traits>
+inline std::enable_if_t<!traits::supported>
decode(std::set<T,Comp,Alloc>& s, bufferlist::iterator& p)
{
__u32 n;
}
}
-template<class T, class Comp, class Alloc, typename traits=denc_traits<T>>
+template<class T, class Comp, class Alloc, typename traits>
inline typename std::enable_if<!traits::supported>::type
encode_nohead(const std::set<T,Comp,Alloc>& s, bufferlist& bl)
{
for (auto p = s.begin(); p != s.end(); ++p)
encode(*p, bl);
}
-template<class T, class Comp, class Alloc, typename traits=denc_traits<T>>
-inline typename std::enable_if<!traits::supported>::type
+template<class T, class Comp, class Alloc, typename traits>
+inline std::enable_if_t<!traits::supported>
decode_nohead(int len, std::set<T,Comp,Alloc>& s, bufferlist::iterator& p)
{
for (int i=0; i<len; i++) {
}
// boost::container::flat_set<T>
-template<class T, class Comp, class Alloc, typename traits=denc_traits<T>>
-inline typename std::enable_if<!traits::supported>::type
+template<class T, class Comp, class Alloc, typename traits>
+inline std::enable_if_t<!traits::supported>
encode(const boost::container::flat_set<T, Comp, Alloc>& s, bufferlist& bl)
{
__u32 n = (__u32)(s.size());
for (const auto& e : s)
encode(e, bl);
}
-template<class T, class Comp, class Alloc, typename traits=denc_traits<T>>
-inline typename std::enable_if<!traits::supported>::type
+template<class T, class Comp, class Alloc, typename traits>
+inline std::enable_if_t<!traits::supported>
decode(boost::container::flat_set<T, Comp, Alloc>& s, bufferlist::iterator& p)
{
__u32 n;
}
}
-template<class T, class Comp, class Alloc, typename traits=denc_traits<T>>
-inline typename std::enable_if<!traits::supported>::type
+template<class T, class Comp, class Alloc, typename traits>
+inline std::enable_if_t<!traits::supported>
encode_nohead(const boost::container::flat_set<T, Comp, Alloc>& s,
bufferlist& bl)
{
for (const auto& e : s)
encode(e, bl);
}
-template<class T, class Comp, class Alloc, typename traits=denc_traits<T>>
-inline typename std::enable_if<!traits::supported>::type
+template<class T, class Comp, class Alloc, typename traits>
+inline std::enable_if_t<!traits::supported>
decode_nohead(int len, boost::container::flat_set<T, Comp, Alloc>& s,
bufferlist::iterator& p)
{
}
}
-// vector (pointers)
-/*template<class T>
-inline void encode(const std::vector<T*>& v, bufferlist& bl)
-{
- __u32 n = v.size();
- encode(n, bl);
- for (typename std::vector<T*>::const_iterator p = v.begin(); p != v.end(); ++p)
- encode(**p, bl);
-}
-template<class T>
-inline void decode(std::vector<T*>& v, bufferlist::iterator& p)
-{
- __u32 n;
- decode(n, p);
- v.resize(n);
- for (__u32 i=0; i<n; i++)
- v[i] = new T(p);
-}
-*/
-// std::vector<T>
-template<class T, class Alloc, typename traits=denc_traits<T>>
-inline typename std::enable_if<!traits::supported>::type
+template<class T, class Alloc, typename traits>
+inline std::enable_if_t<!traits::supported>
encode(const std::vector<T,Alloc>& v, bufferlist& bl, uint64_t features)
{
__u32 n = (__u32)(v.size());
for (auto p = v.begin(); p != v.end(); ++p)
encode(*p, bl, features);
}
-template<class T, class Alloc, typename traits=denc_traits<T>>
-inline typename std::enable_if<!traits::supported>::type
+template<class T, class Alloc, typename traits>
+inline std::enable_if_t<!traits::supported>
encode(const std::vector<T,Alloc>& v, bufferlist& bl)
{
__u32 n = (__u32)(v.size());
for (auto p = v.begin(); p != v.end(); ++p)
encode(*p, bl);
}
-template<class T, class Alloc, typename traits=denc_traits<T>>
-inline typename std::enable_if<!traits::supported>::type
+template<class T, class Alloc, typename traits>
+inline std::enable_if_t<!traits::supported>
decode(std::vector<T,Alloc>& v, bufferlist::iterator& p)
{
__u32 n;
decode(v[i], p);
}
-template<class T, class Alloc, typename traits=denc_traits<T>>
-inline typename std::enable_if<!traits::supported>::type
+template<class T, class Alloc, typename traits>
+inline std::enable_if_t<!traits::supported>
encode_nohead(const std::vector<T,Alloc>& v, bufferlist& bl)
{
for (auto p = v.begin(); p != v.end(); ++p)
encode(*p, bl);
}
-template<class T, class Alloc, typename traits=denc_traits<T>>
-inline typename std::enable_if<!traits::supported>::type
+template<class T, class Alloc, typename traits>
+inline std::enable_if_t<!traits::supported>
decode_nohead(int len, std::vector<T,Alloc>& v, bufferlist::iterator& p)
{
v.resize(len);
}
}
-// map (pointers)
-/*
-template<class T, class U>
-inline void encode(const std::map<T,U*>& m, bufferlist& bl)
-{
- __u32 n = m.size();
- encode(n, bl);
- for (typename std::map<T,U*>::const_iterator p = m.begin(); p != m.end(); ++p) {
- encode(p->first, bl);
- encode(*p->second, bl);
- }
-}
-template<class T, class U>
-inline void decode(std::map<T,U*>& m, bufferlist::iterator& p)
-{
- __u32 n;
- decode(n, p);
- m.clear();
- while (n--) {
- T k;
- decode(k, p);
- m[k] = new U(p);
- }
- }*/
-
// map
template<class T, class U, class Comp, class Alloc,
- typename t_traits=denc_traits<T>, typename u_traits=denc_traits<U>>
-inline typename std::enable_if<!t_traits::supported ||
- !u_traits::supported>::type
+ typename t_traits, typename u_traits>
+inline std::enable_if_t<!t_traits::supported ||
+ !u_traits::supported>
encode(const std::map<T,U,Comp,Alloc>& m, bufferlist& bl)
{
__u32 n = (__u32)(m.size());
}
}
template<class T, class U, class Comp, class Alloc,
- typename t_traits=denc_traits<T>, typename u_traits=denc_traits<U>>
-inline typename std::enable_if<!t_traits::supported ||
- !u_traits::supported>::type
+ typename t_traits, typename u_traits>
+inline std::enable_if_t<!t_traits::supported || !u_traits::supported>
encode(const std::map<T,U,Comp,Alloc>& m, bufferlist& bl, uint64_t features)
{
__u32 n = (__u32)(m.size());
}
}
template<class T, class U, class Comp, class Alloc,
- typename t_traits=denc_traits<T>, typename u_traits=denc_traits<U>>
-inline typename std::enable_if<!t_traits::supported ||
- !u_traits::supported>::type
+ typename t_traits, typename u_traits>
+inline std::enable_if_t<!t_traits::supported || !u_traits::supported>
decode(std::map<T,U,Comp,Alloc>& m, bufferlist::iterator& p)
{
__u32 n;
}
}
template<class T, class U, class Comp, class Alloc,
- typename t_traits=denc_traits<T>, typename u_traits=denc_traits<U>>
-inline typename std::enable_if<!t_traits::supported ||
- !u_traits::supported>::type
+ typename t_traits, typename u_traits>
+inline std::enable_if_t<!t_traits::supported || !u_traits::supported>
encode_nohead(const std::map<T,U,Comp,Alloc>& m, bufferlist& bl)
{
for (auto p = m.begin(); p != m.end(); ++p) {
}
}
template<class T, class U, class Comp, class Alloc,
- typename t_traits=denc_traits<T>, typename u_traits=denc_traits<U>>
-inline typename std::enable_if<!t_traits::supported ||
- !u_traits::supported>::type
+ typename t_traits, typename u_traits>
+inline std::enable_if_t<!t_traits::supported || !u_traits::supported>
encode_nohead(const std::map<T,U,Comp,Alloc>& m, bufferlist& bl, uint64_t features)
{
for (auto p = m.begin(); p != m.end(); ++p) {
}
}
template<class T, class U, class Comp, class Alloc,
- typename t_traits=denc_traits<T>, typename u_traits=denc_traits<U>>
-inline typename std::enable_if<!t_traits::supported ||
- !u_traits::supported>::type
+ typename t_traits, typename u_traits>
+inline std::enable_if_t<!t_traits::supported || !u_traits::supported>
decode_nohead(int n, std::map<T,U,Comp,Alloc>& m, bufferlist::iterator& p)
{
m.clear();
// boost::container::flat-map
template<class T, class U, class Comp, class Alloc,
- typename t_traits=denc_traits<T>, typename u_traits=denc_traits<U>>
- inline typename std::enable_if<!t_traits::supported ||
- !u_traits::supported>::type
+ typename t_traits, typename u_traits>
+ inline std::enable_if_t<!t_traits::supported || !u_traits::supported>
encode(const boost::container::flat_map<T,U,Comp,Alloc>& m, bufferlist& bl)
{
__u32 n = (__u32)(m.size());
}
}
template<class T, class U, class Comp, class Alloc,
- typename t_traits=denc_traits<T>, typename u_traits=denc_traits<U>>
- inline typename std::enable_if<!t_traits::supported ||
- !u_traits::supported>::type
+ typename t_traits, typename u_traits>
+ inline std::enable_if_t<!t_traits::supported || !u_traits::supported>
encode(const boost::container::flat_map<T,U,Comp,Alloc>& m, bufferlist& bl,
uint64_t features)
{
}
}
template<class T, class U, class Comp, class Alloc,
- typename t_traits=denc_traits<T>, typename u_traits=denc_traits<U>>
- inline typename std::enable_if<!t_traits::supported ||
- !u_traits::supported>::type
+ typename t_traits, typename u_traits>
+ inline std::enable_if_t<!t_traits::supported || !u_traits::supported>
decode(boost::container::flat_map<T,U,Comp,Alloc>& m, bufferlist::iterator& p)
{
__u32 n;
}
}
template<class T, class U, class Comp, class Alloc,
- typename t_traits=denc_traits<T>, typename u_traits=denc_traits<U>>
- inline typename std::enable_if<!t_traits::supported ||
- !u_traits::supported>::type
+ typename t_traits, typename u_traits>
+ inline std::enable_if_t<!t_traits::supported || !u_traits::supported>
encode_nohead(const boost::container::flat_map<T,U,Comp,Alloc>& m,
bufferlist& bl)
{
}
}
template<class T, class U, class Comp, class Alloc,
- typename t_traits=denc_traits<T>, typename u_traits=denc_traits<U>>
- inline typename std::enable_if<!t_traits::supported ||
- !u_traits::supported>::type
+ typename t_traits, typename u_traits>
+ inline std::enable_if_t<!t_traits::supported || !u_traits::supported>
encode_nohead(const boost::container::flat_map<T,U,Comp,Alloc>& m,
bufferlist& bl, uint64_t features)
{
}
}
template<class T, class U, class Comp, class Alloc,
- typename t_traits=denc_traits<T>, typename u_traits=denc_traits<U>>
-inline typename std::enable_if<!t_traits::supported ||
- !u_traits::supported>::type
+ typename t_traits, typename u_traits>
+inline std::enable_if_t<!t_traits::supported || !u_traits::supported>
decode_nohead(int n, boost::container::flat_map<T,U,Comp,Alloc>& m,
bufferlist::iterator& p)
{
}
// std::array<T, N>
-template<class T, size_t N, typename traits = denc_traits<T>>
-inline typename std::enable_if<!traits::supported>::type
+template<class T, size_t N, typename traits>
+inline std::enable_if_t<!traits::supported>
encode(const std::array<T, N>& v, bufferlist& bl, uint64_t features)
{
for (const auto& e : v)
encode(e, bl, features);
}
-template<class T, size_t N, typename traits = denc_traits<T>>
-inline typename std::enable_if<!traits::supported>::type
+template<class T, size_t N, typename traits>
+inline std::enable_if_t<!traits::supported>
encode(const std::array<T, N>& v, bufferlist& bl)
{
for (const auto& e : v)
encode(e, bl);
}
-template<class T, size_t N, typename traits = denc_traits<T>>
-inline typename std::enable_if<!traits::supported>::type
+template<class T, size_t N, typename traits>
+inline std::enable_if_t<!traits::supported>
decode(std::array<T, N>& v, bufferlist::iterator& p)
{
for (auto& e : v)
decode(e, p);
}
-
+}
/*
* guards
* @param bl bufferlist to encode to
*/
#define ENCODE_START(v, compat, bl) \
+ using ::ceph::encode; \
__u8 struct_v = v, struct_compat = compat; \
- ::encode(struct_v, (bl)); \
- ::encode(struct_compat, (bl)); \
- buffer::list::iterator struct_compat_it = (bl).end(); \
+ encode(struct_v, (bl)); \
+ encode(struct_compat, (bl)); \
+ ::ceph::buffer::list::iterator struct_compat_it = (bl).end(); \
struct_compat_it.advance(-1); \
ceph_le32 struct_len; \
struct_len = 0; \
- ::encode(struct_len, (bl)); \
- buffer::list::iterator struct_len_it = (bl).end(); \
+ encode(struct_len, (bl)); \
+ ::ceph::buffer::list::iterator struct_len_it = (bl).end(); \
struct_len_it.advance(-4); \
do {
*/
#define DECODE_OLDEST(oldestv) \
if (struct_v < oldestv) \
- throw buffer::malformed_input(DECODE_ERR_OLDVERSION(__PRETTY_FUNCTION__, v, oldestv));
+ throw ::ceph::buffer::malformed_input(DECODE_ERR_OLDVERSION(__PRETTY_FUNCTION__, v, oldestv));
/**
* start a decoding block
*/
#define DECODE_START(v, bl) \
__u8 struct_v, struct_compat; \
- ::decode(struct_v, bl); \
- ::decode(struct_compat, bl); \
+ using ::ceph::decode; \
+ decode(struct_v, bl); \
+ decode(struct_compat, bl); \
if (v < struct_compat) \
throw buffer::malformed_input(DECODE_ERR_OLDVERSION(__PRETTY_FUNCTION__, v, struct_compat)); \
__u32 struct_len; \
- ::decode(struct_len, bl); \
+ decode(struct_len, bl); \
if (struct_len > bl.get_remaining()) \
- throw buffer::malformed_input(DECODE_ERR_PAST(__PRETTY_FUNCTION__)); \
+ throw ::ceph::buffer::malformed_input(DECODE_ERR_PAST(__PRETTY_FUNCTION__)); \
unsigned struct_end = bl.get_off() + struct_len; \
do {
#define __DECODE_START_LEGACY_COMPAT_LEN(v, compatv, lenv, skip_v, bl) \
+ using ::ceph::decode; \
__u8 struct_v; \
- ::decode(struct_v, bl); \
+ decode(struct_v, bl); \
if (struct_v >= compatv) { \
__u8 struct_compat; \
- ::decode(struct_compat, bl); \
+ decode(struct_compat, bl); \
if (v < struct_compat) \
throw buffer::malformed_input(DECODE_ERR_OLDVERSION(__PRETTY_FUNCTION__, v, struct_compat)); \
} else if (skip_v) { \
unsigned struct_end = 0; \
if (struct_v >= lenv) { \
__u32 struct_len; \
- ::decode(struct_len, bl); \
+ decode(struct_len, bl); \
if (struct_len > bl.get_remaining()) \
throw buffer::malformed_input(DECODE_ERR_PAST(__PRETTY_FUNCTION__)); \
struct_end = bl.get_off() + struct_len; \
bl.advance(struct_end - bl.get_off()); \
}
+namespace ceph {
+
/*
* Encoders/decoders to read from current offset in a file handle and
* encode/decode the data according to argument types.
decode(bp, bli);
return bl.length();
}
+}
+
+using ceph::encode;
+using ceph::decode;
+using ceph::encode_nohead;
+using ceph::decode_nohead;
#endif