blob: 3c0c622b056a049c78acfaddc28f1d2a165b8d7b [file] [log] [blame]
Tom Joseph15d88fb2016-08-05 03:30:04 -05001#pragma once
2
3#include <endian.h>
4#include <stdint.h>
5
6namespace endian
7{
8namespace details
9{
10template <typename T>
11struct convert
12{
13 static T to_ipmi(T) = delete;
14 static T from_ipmi(T) = delete;
15 static T to_network(T) = delete;
16 static T from_network(T) = delete;
17};
18
19template<> struct convert<uint16_t>
20{
21 static uint16_t to_ipmi(uint16_t i) { return htole16(i); };
22 static uint16_t from_ipmi(uint16_t i) { return le16toh(i); };
23 static uint16_t to_network(uint16_t i) { return htobe16(i); };
24 static uint16_t from_network(uint16_t i) { return be16toh(i); };
25};
26
27template<> struct convert<uint32_t>
28{
29 static uint32_t to_ipmi(uint32_t i) { return htole32(i); };
30 static uint32_t from_ipmi(uint32_t i) { return le32toh(i); };
31 static uint32_t to_network(uint32_t i) { return htobe32(i); };
32 static uint32_t from_network(uint32_t i) { return be32toh(i); };
33};
34}
35
36template<typename T> T to_ipmi(T i)
37{
38 return details::convert<T>::to_ipmi(i);
39}
40
41template<typename T> T from_ipmi(T i)
42{
43 return details::convert<T>::from_ipmi(i);
44}
45
46template<typename T> T to_network(T i)
47{
48 return details::convert<T>::to_network(i);
49}
50template<typename T> T from_network(T i)
51{
52 return details::convert<T>::from_network(i);
53}
54}