]>
Commit | Line | Data |
---|---|---|
7c673cae FG |
1 | // -*- mode:C++; tab-width:8; c-basic-offset:2; indent-tabs-mode:t -*- |
2 | ||
3 | #pragma once | |
4 | ||
20effc67 | 5 | #include <boost/endian/conversion.hpp> |
7c673cae | 6 | |
20effc67 | 7 | #include "int_types.h" |
7c673cae | 8 | |
7c673cae | 9 | template<typename T> |
20effc67 TL |
10 | inline T swab(T val) { |
11 | return boost::endian::endian_reverse(val); | |
7c673cae | 12 | } |
7c673cae FG |
13 | |
14 | template<typename T> | |
15 | struct ceph_le { | |
9f95a23c | 16 | private: |
7c673cae | 17 | T v; |
9f95a23c | 18 | public: |
20effc67 TL |
19 | ceph_le() = default; |
20 | explicit ceph_le(T nv) | |
21 | : v{boost::endian::native_to_little(nv)} | |
22 | {} | |
7c673cae | 23 | ceph_le<T>& operator=(T nv) { |
20effc67 | 24 | v = boost::endian::native_to_little(nv); |
7c673cae FG |
25 | return *this; |
26 | } | |
20effc67 | 27 | operator T() const { return boost::endian::little_to_native(v); } |
9f95a23c TL |
28 | friend inline bool operator==(ceph_le a, ceph_le b) { |
29 | return a.v == b.v; | |
30 | } | |
7c673cae FG |
31 | } __attribute__ ((packed)); |
32 | ||
7c673cae FG |
33 | using ceph_le64 = ceph_le<__u64>; |
34 | using ceph_le32 = ceph_le<__u32>; | |
35 | using ceph_le16 = ceph_le<__u16>; | |
36 | ||
f67539c2 TL |
37 | using ceph_les64 = ceph_le<__s64>; |
38 | using ceph_les32 = ceph_le<__s32>; | |
39 | using ceph_les16 = ceph_le<__s16>; | |
40 | ||
f67539c2 TL |
41 | inline ceph_les64 init_les64(__s64 x) { |
42 | ceph_les64 v; | |
43 | v = x; | |
44 | return v; | |
45 | } | |
46 | inline ceph_les32 init_les32(__s32 x) { | |
47 | ceph_les32 v; | |
48 | v = x; | |
49 | return v; | |
50 | } | |
51 | inline ceph_les16 init_les16(__s16 x) { | |
52 | ceph_les16 v; | |
53 | v = x; | |
54 | return v; | |
55 | } |