__le32 middle_crc;
__le32 data_crc;
} __attribute__ ((packed)) sigblock = {
- 1, mswab64(AUTH_ENC_MAGIC), mswab32(4*4),
- mswab32(header.crc), mswab32(footer.front_crc),
- mswab32(footer.middle_crc), mswab32(footer.data_crc)
+ 1, mswab(AUTH_ENC_MAGIC), mswab<uint32_t>(4*4),
+ mswab<uint32_t>(header.crc), mswab<uint32_t>(footer.front_crc),
+ mswab<uint32_t>(footer.middle_crc), mswab<uint32_t>(footer.data_crc)
};
bufferlist bl_plaintext;
bl_plaintext.append(buffer::create_static(sizeof(sigblock), (char*)&sigblock));
-/*
- * byteorder.h
- *
- * LGPL 2
- */
+// -*- mode:C++; tab-width:8; c-basic-offset:2; indent-tabs-mode:t -*-
-#ifndef CEPH_BYTEORDER_H
-#define CEPH_BYTEORDER_H
+#pragma once
+#include <type_traits>
#include "acconfig.h"
#include "int_types.h"
-static __inline__ __u16 swab16(__u16 val)
-{
+#ifdef __GNUC__
+template<typename T>
+inline typename std::enable_if<sizeof(T) == sizeof(uint16_t), T>::type
+swab(T val) {
+ return __builtin_bswap16(val);
+}
+template<typename T>
+inline typename std::enable_if<sizeof(T) == sizeof(uint32_t), T>::type
+swab(T val) {
+ return __builtin_bswap32(val);
+}
+template<typename T>
+inline typename std::enable_if<sizeof(T) == sizeof(uint64_t), T>::type
+swab(T val) {
+ return __builtin_bswap64(val);
+}
+#else
+template<typename T>
+inline typename std::enable_if<sizeof(T) == sizeof(uint16_t), T>::type
+swab(T val) {
return (val >> 8) | (val << 8);
}
-static __inline__ __u32 swab32(__u32 val)
-{
+template<typename T>
+inline typename std::enable_if<sizeof(T) == sizeof(uint32_t), T>::type
+swab(T val) {
return (( val >> 24) |
((val >> 8) & 0xff00) |
((val << 8) & 0xff0000) |
((val << 24)));
}
-static __inline__ uint64_t swab64(uint64_t val)
-{
+template<typename T>
+inline typename std::enable_if<sizeof(T) == sizeof(uint64_t), T>::type
+swab(T val) {
return (( val >> 56) |
((val >> 40) & 0xff00ull) |
((val >> 24) & 0xff0000ull) |
((val << 40) & 0xff000000000000ull) |
((val << 56)));
}
+#endif
// mswab == maybe swab (if not LE)
#ifdef CEPH_BIG_ENDIAN
-# define mswab64(a) swab64(a)
-# define mswab32(a) swab32(a)
-# define mswab16(a) swab16(a)
-#elif defined(CEPH_LITTLE_ENDIAN)
-# define mswab64(a) (a)
-# define mswab32(a) (a)
-# define mswab16(a) (a)
+template<typename T>
+inline T mswab(T val) {
+ return swab(val);
+}
#else
-# error "Could not determine endianess"
+template<typename T>
+inline T mswab(T val) {
+ return val;
+}
#endif
-#ifdef __cplusplus
-
#define MAKE_LE_CLASS(bits) \
- struct ceph_le##bits { \
+ struct ceph_le##bits { \
__u##bits v; \
ceph_le##bits &operator=(__u##bits nv) { \
- v = mswab##bits(nv); \
+ v = mswab(nv); \
return *this; \
} \
- operator __u##bits() const { return mswab##bits(v); } \
+ operator __u##bits() const { return mswab(v); } \
} __attribute__ ((packed)); \
- static inline bool operator==(ceph_le##bits a, ceph_le##bits b) { \
+ static inline bool operator==(ceph_le##bits a, ceph_le##bits b) { \
return a.v == b.v; \
}
MAKE_LE_CLASS(16)
#undef MAKE_LE_CLASS
-#endif /* __cplusplus */
-
-#define init_le64(x) { (__u64)mswab64(x) }
-#define init_le32(x) { (__u32)mswab32(x) }
-#define init_le16(x) { (__u16)mswab16(x) }
+inline __u64 init_le64(__u64 x) {
+ return mswab<__u64>(x);
+}
+inline __u32 init_le32(__u32 x) {
+ return mswab<__u32>(x);
+}
+inline __u16 init_le16(__u16 x) {
+ return mswab<__u16>(x);
+}
/*
#define cpu_to_le64(x) (x)
#define le64_to_cpu(x) ((uint64_t)x)
#define le32_to_cpu(x) ((__u32)x)
#define le16_to_cpu(x) ((__u16)x)
-
-#endif
#if defined(CEPH_LITTLE_ENDIAN)
uint32_t length;
::decode(length, it);
- length = swab32(length);
+ length = swab(length);
str.clear();
it.copy(length, str);
#else
::decode(id, it);
::decode(time_delta, it);
if (byte_swap_required(version)) {
- id = swab32(id);
- time_delta = swab64(time_delta);
+ id = swab(id);
+ time_delta = swab(time_delta);
}
}
}
if (byte_swap_required(version)) {
- id = swab32(id);
- thread_id = swab64(thread_id);
+ id = swab(id);
+ thread_id = swab(thread_id);
uint32_t dep_count;
::decode(dep_count, it);
- dep_count = swab32(dep_count);
+ dep_count = swab(dep_count);
dependencies.resize(dep_count);
for (uint32_t i = 0; i < dep_count; ++i) {
dependencies[i].decode(0, it);
ActionBase::decode(version, it);
::decode(imagectx_id, it);
if (byte_swap_required(version)) {
- imagectx_id = swab64(imagectx_id);
+ imagectx_id = swab(imagectx_id);
}
}
::decode(offset, it);
::decode(length, it);
if (byte_swap_required(version)) {
- offset = swab64(offset);
- length = swab64(length);
+ offset = swab(offset);
+ length = swab(length);
}
}