]> git.proxmox.com Git - ceph.git/blob - ceph/src/include/encoding_btree.h
add subtree-ish sources for 12.0.3
[ceph.git] / ceph / src / include / encoding_btree.h
1 // -*- mode:C++; tab-width:8; c-basic-offset:2; indent-tabs-mode:t -*-
2 // vim: ts=8 sw=2 smarttab
3
4 #ifndef CEPH_INCLUDE_ENCODING_BTREE_H
5 #define CEPH_INCLUDE_ENCODING_BTREE_H
6
7 #include "include/cpp-btree/btree_map.h"
8
9 template<class T, class U>
10 inline void encode(const btree::btree_map<T,U>& m, bufferlist& bl)
11 {
12 __u32 n = (__u32)(m.size());
13 encode(n, bl);
14 for (typename btree::btree_map<T,U>::const_iterator p = m.begin(); p != m.end(); ++p) {
15 encode(p->first, bl);
16 encode(p->second, bl);
17 }
18 }
19 template<class T, class U>
20 inline void encode(const btree::btree_map<T,U>& m, bufferlist& bl, uint64_t features)
21 {
22 __u32 n = (__u32)(m.size());
23 encode(n, bl);
24 for (typename btree::btree_map<T,U>::const_iterator p = m.begin(); p != m.end(); ++p) {
25 encode(p->first, bl, features);
26 encode(p->second, bl, features);
27 }
28 }
29 template<class T, class U>
30 inline void decode(btree::btree_map<T,U>& m, bufferlist::iterator& p)
31 {
32 __u32 n;
33 decode(n, p);
34 m.clear();
35 while (n--) {
36 T k;
37 decode(k, p);
38 decode(m[k], p);
39 }
40 }
41 template<class T, class U>
42 inline void encode_nohead(const btree::btree_map<T,U>& m, bufferlist& bl)
43 {
44 for (typename btree::btree_map<T,U>::const_iterator p = m.begin(); p != m.end(); ++p) {
45 encode(p->first, bl);
46 encode(p->second, bl);
47 }
48 }
49 template<class T, class U>
50 inline void decode_nohead(int n, btree::btree_map<T,U>& m, bufferlist::iterator& p)
51 {
52 m.clear();
53 while (n--) {
54 T k;
55 decode(k, p);
56 decode(m[k], p);
57 }
58 }
59
60 #endif