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
|
#pragma once
#undef ntohll
#define ntohll(x) ((((UInt64)ntohl((u_long)x)) << 32) + ntohl(x >> 32))
// Changes endianness
inline UInt64 HostToNetwork8(const void * a_Value)
{
unsigned long long __HostToNetwork8;
memcpy( &__HostToNetwork8, a_Value, sizeof( __HostToNetwork8));
__HostToNetwork8 = (( ( (unsigned long long)htonl((u_long)__HostToNetwork8)) << 32) + htonl(__HostToNetwork8 >> 32));
return __HostToNetwork8;
}
inline UInt32 HostToNetwork4(const void* a_Value)
{
unsigned int __HostToNetwork4;
memcpy( &__HostToNetwork4, a_Value, sizeof( __HostToNetwork4));
__HostToNetwork4 = ntohl( __HostToNetwork4);
return __HostToNetwork4;
}
inline double NetworkToHostDouble8(const void * a_Value)
{
UInt64 buf = 0;
memcpy(&buf, a_Value, 8);
buf = ntohll(buf);
double x;
memcpy(&x, &buf, sizeof(double));
return x;
}
inline Int64 NetworkToHostLong8(const void * a_Value)
{
UInt64 buf;
memcpy(&buf, a_Value, 8);
buf = ntohll(buf);
return *reinterpret_cast<Int64 *>(&buf);
}
inline float NetworkToHostFloat4(const void * a_Value)
{
UInt32 buf;
float x;
memcpy(&buf, a_Value, 4);
buf = ntohl(buf);
memcpy(&x, &buf, sizeof(float));
return x;
}
|