forked from LiXizhi/TMInterface
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathbyteswap.hpp
More file actions
123 lines (99 loc) · 1.63 KB
/
Copy pathbyteswap.hpp
File metadata and controls
123 lines (99 loc) · 1.63 KB
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
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
/**
*============================================================
* @file byteswap.hpp
* @brief 用于进行字节序转换。如果原本是网络序,则转成本机序;如果原本是本机序,则转成网络序。\n
* 用法:val = bswap(val);。可以对任意大小的整数类型进行字节序转换。
*
* compiler gcc4.1.2
* platform Linux
*
* copyright: TaoMee, Inc. ShangHai CN. All rights reserved.
*
*============================================================
*/
#pragma once
#ifndef WIN32
extern "C" {
#include <stdint.h> // C99
#include <byteswap.h> // Linux
}
namespace taomee {
inline int8 bswap(int8 x)
{
return x;
}
inline uint8 bswap(uint8 x)
{
return x;
}
inline int16 bswap(int16 x)
{
return bswap_16(x);
}
inline uint16 bswap(uint16 x)
{
return bswap_16(x);
}
inline int32 bswap(int32 x)
{
return bswap_32(x);
}
inline uint32 bswap(uint32 x)
{
return bswap_32(x);
}
inline int64 bswap(int64 x)
{
return bswap_64(x);
}
inline uint64 bswap(uint64 x)
{
return bswap_64(x);
}
#if __WORDSIZE == 32
inline long bswap(long x)
{
return bswap_32(x);
}
inline unsigned long bswap(unsigned long x)
{
return bswap_32(x);
}
#endif
}
#else
namespace taomee {
inline int8 bswap(int8 x)
{
return x;
}
inline uint8 bswap(uint8 x)
{
return x;
}
inline int16 bswap(int16 x)
{
return 0;
}
inline uint16 bswap(uint16 x)
{
return 0;
}
inline int32 bswap(int32 x)
{
return 0;
}
inline uint32 bswap(uint32 x)
{
return 0;
}
inline int64 bswap(int64 x)
{
return 0;
}
inline uint64 bswap(uint64 x)
{
return 0;
}
} // namespace taomee
#endif