Algorithm
Review
Tips
Share
Ceph的encoding宏定义妙用
宏定义do_while(false)套娃
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
int a = A; \
printf("hello a=%d\n", a); \
do {
// 这中间还套娃了很多层do,while,这是我没有想到了
} while(false);
int main() {
cout << "hello world" << endl;
ENCODE_START(100)
DECODE_FINISH()
return 0;
}震惊宏定义缩短定义的方法
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21// -----------------------------------
// int types
inline void encode(type v, bufferlist& bl, uint64_t features=0) { \
ceph_#
e = v; \
encode_raw(e, bl); \
} \
inline void decode(type &v, bufferlist::iterator& p) { \
ceph_#
decode_raw(e, p); \
v = e; \
}
WRITE_INTTYPE_ENCODER(uint64_t, le64)
WRITE_INTTYPE_ENCODER(int64_t, le64)
WRITE_INTTYPE_ENCODER(uint32_t, le32)
WRITE_INTTYPE_ENCODER(int32_t, le32)
WRITE_INTTYPE_ENCODER(uint16_t, le16)
WRITE_INTTYPE_ENCODER(int16_t, le16)