2012-06-14 09:06:06 -04:00
|
|
|
|
|
|
|
#pragma once
|
|
|
|
|
2014-07-26 06:42:42 -04:00
|
|
|
#undef ntohll
|
2014-04-04 04:13:25 -04:00
|
|
|
#define ntohll(x) ((((UInt64)ntohl((u_long)x)) << 32) + ntohl(x >> 32))
|
|
|
|
|
2012-06-14 09:06:06 -04:00
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// Changes endianness
|
2014-04-04 04:13:25 -04:00
|
|
|
inline UInt64 HostToNetwork8(const void * a_Value)
|
2012-06-14 09:06:06 -04:00
|
|
|
{
|
|
|
|
unsigned long long __HostToNetwork8;
|
2014-07-21 09:19:48 -04:00
|
|
|
memcpy( &__HostToNetwork8, a_Value, sizeof( __HostToNetwork8));
|
|
|
|
__HostToNetwork8 = (( ( (unsigned long long)htonl((u_long)__HostToNetwork8)) << 32) + htonl(__HostToNetwork8 >> 32));
|
2012-06-14 09:06:06 -04:00
|
|
|
return __HostToNetwork8;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
2014-07-21 09:19:48 -04:00
|
|
|
inline UInt32 HostToNetwork4(const void* a_Value)
|
2012-06-14 09:06:06 -04:00
|
|
|
{
|
|
|
|
unsigned int __HostToNetwork4;
|
2014-07-21 09:19:48 -04:00
|
|
|
memcpy( &__HostToNetwork4, a_Value, sizeof( __HostToNetwork4));
|
|
|
|
__HostToNetwork4 = ntohl( __HostToNetwork4);
|
2012-06-14 09:06:06 -04:00
|
|
|
return __HostToNetwork4;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
2014-04-04 04:13:25 -04:00
|
|
|
inline double NetworkToHostDouble8(const void * a_Value)
|
2012-06-14 09:06:06 -04:00
|
|
|
{
|
2014-04-04 04:13:25 -04:00
|
|
|
UInt64 buf = 0;
|
|
|
|
memcpy(&buf, a_Value, 8);
|
2012-06-14 09:06:06 -04:00
|
|
|
buf = ntohll(buf);
|
|
|
|
double x;
|
|
|
|
memcpy(&x, &buf, sizeof(double));
|
|
|
|
return x;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
2014-04-04 04:13:25 -04:00
|
|
|
inline Int64 NetworkToHostLong8(const void * a_Value)
|
2012-06-14 09:06:06 -04:00
|
|
|
{
|
2014-04-04 04:13:25 -04:00
|
|
|
UInt64 buf;
|
2014-04-05 16:34:05 -04:00
|
|
|
memcpy(&buf, a_Value, 8);
|
2012-06-14 09:06:06 -04:00
|
|
|
buf = ntohll(buf);
|
2014-04-04 04:13:25 -04:00
|
|
|
return *reinterpret_cast<Int64 *>(&buf);
|
2012-06-14 09:06:06 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
2014-04-04 04:13:25 -04:00
|
|
|
inline float NetworkToHostFloat4(const void * a_Value)
|
2012-06-14 09:06:06 -04:00
|
|
|
{
|
2014-04-04 04:13:25 -04:00
|
|
|
UInt32 buf;
|
|
|
|
float x;
|
2014-04-05 16:34:05 -04:00
|
|
|
memcpy(&buf, a_Value, 4);
|
2014-04-04 04:13:25 -04:00
|
|
|
buf = ntohl(buf);
|
|
|
|
memcpy(&x, &buf, sizeof(float));
|
2012-06-14 09:06:06 -04:00
|
|
|
return x;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|