From: Kefu Chai Date: Tue, 9 May 2017 08:08:49 +0000 (+0800) Subject: byteorder: refactor ceph_le{16,32,64} using template X-Git-Tag: v12.0.3~23^2 X-Git-Url: http://git-server-git.apps.pok.os.sepia.ceph.com/?a=commitdiff_plain;h=refs%2Fpull%2F15012%2Fhead;p=ceph.git byteorder: refactor ceph_le{16,32,64} using template to improve the readablity and easier for debugging. Signed-off-by: Kefu Chai --- diff --git a/src/include/byteorder.h b/src/include/byteorder.h index bbc8a2ef4443..867486016686 100644 --- a/src/include/byteorder.h +++ b/src/include/byteorder.h @@ -64,23 +64,24 @@ inline T mswab(T val) { } #endif -#define MAKE_LE_CLASS(bits) \ - struct ceph_le##bits { \ - __u##bits v; \ - ceph_le##bits &operator=(__u##bits nv) { \ - v = mswab(nv); \ - return *this; \ - } \ - operator __u##bits() const { return mswab(v); } \ - } __attribute__ ((packed)); \ - static inline bool operator==(ceph_le##bits a, ceph_le##bits b) { \ - return a.v == b.v; \ +template +struct ceph_le { + T v; + ceph_le& operator=(T nv) { + v = mswab(nv); + return *this; } - -MAKE_LE_CLASS(64) -MAKE_LE_CLASS(32) -MAKE_LE_CLASS(16) -#undef MAKE_LE_CLASS + operator T() const { return mswab(v); } +} __attribute__ ((packed)); + +template +inline bool operator==(ceph_le a, ceph_le b) { + return a.v == b.v; +} + +using ceph_le64 = ceph_le<__u64>; +using ceph_le32 = ceph_le<__u32>; +using ceph_le16 = ceph_le<__u16>; inline __u64 init_le64(__u64 x) { return mswab<__u64>(x);