summaryrefslogtreecommitdiffstats
path: root/endian.hpp
blob: 446e879ea4435ef9f2a44a746c3185c03c6a3ca3 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
#pragma once

#include <endian.h>
#include <stdint.h>

namespace endian
{
namespace details
{
template <typename T>
struct convert
{
    static T to_ipmi(T) = delete;
    static T from_ipmi(T) = delete;
    static T to_network(T) = delete;
    static T from_network(T) = delete;
};

template <>
struct convert<uint16_t>
{
    static uint16_t to_ipmi(uint16_t i)
    {
        return htole16(i);
    };
    static uint16_t from_ipmi(uint16_t i)
    {
        return le16toh(i);
    };
    static uint16_t to_network(uint16_t i)
    {
        return htobe16(i);
    };
    static uint16_t from_network(uint16_t i)
    {
        return be16toh(i);
    };
};

template <>
struct convert<uint32_t>
{
    static uint32_t to_ipmi(uint32_t i)
    {
        return htole32(i);
    };
    static uint32_t from_ipmi(uint32_t i)
    {
        return le32toh(i);
    };
    static uint32_t to_network(uint32_t i)
    {
        return htobe32(i);
    };
    static uint32_t from_network(uint32_t i)
    {
        return be32toh(i);
    };
};
} // namespace details

template <typename T>
T to_ipmi(T i)
{
    return details::convert<T>::to_ipmi(i);
}

template <typename T>
T from_ipmi(T i)
{
    return details::convert<T>::from_ipmi(i);
}

template <typename T>
T to_network(T i)
{
    return details::convert<T>::to_network(i);
}
template <typename T>
T from_network(T i)
{
    return details::convert<T>::from_network(i);
}
} // namespace endian
OpenPOWER on IntegriCloud