9#include <infiniband/verbs.h>
14static inline uint16_t ntoh(uint16_t
const &value) { return ::be16toh(value); }
16static inline uint32_t ntoh(uint32_t
const &value) { return ::be32toh(value); }
18static inline uint64_t ntoh(uint64_t
const &value) { return ::be64toh(value); }
20static inline uint16_t hton(uint16_t
const &value) { return ::htobe16(value); }
22static inline uint32_t hton(uint32_t
const &value) { return ::htobe32(value); }
24static inline uint64_t hton(uint64_t
const &value) { return ::htobe64(value); }
26template <
class T,
class It>
27typename std::enable_if<std::is_integral<T>::value>::type
28serialize(T
const &value, It &it) {
29 T nvalue = hton(value);
30 std::copy_n(
reinterpret_cast<uint8_t *
>(&nvalue),
sizeof(T), it);
33template <
class T,
class It>
34typename std::enable_if<std::is_same<T, union ibv_gid>::value>::type
35serialize(T
const &value, It &it) {
36 std::copy_n(
reinterpret_cast<uint8_t
const *
>(&value),
sizeof(T), it);
39template <
class T,
class It>
40typename std::enable_if<std::is_integral<T>::value>::type
41deserialize(It &it, T &value) {
42 std::copy_n(it,
sizeof(T),
reinterpret_cast<uint8_t *
>(&value));
47template <
class T,
class It>
48typename std::enable_if<std::is_same<T, void *>::value>::type
49deserialize(It &it, T &value) {
50 std::copy_n(it,
sizeof(T),
reinterpret_cast<uint8_t *
>(&value));
52 value =
reinterpret_cast<void *
>(ntoh(
reinterpret_cast<uint64_t
>(value)));
55template <
class T,
class It>
56typename std::enable_if<std::is_same<T, union ibv_gid>::value>::type
57deserialize(It &it, T &value) {
58 std::copy_n(it,
sizeof(T),
reinterpret_cast<uint8_t *
>(&value));