2012-06-14 13:06:06 +00:00
|
|
|
|
|
|
|
#pragma once
|
|
|
|
|
2014-07-26 03:42:42 -07:00
|
|
|
#undef ntohll
|
2015-07-09 11:15:37 -06:00
|
|
|
#define ntohll(x) (((static_cast<UInt64>(ntohl(static_cast<UInt32>(x)))) << 32) + ntohl(x >> 32))
|
2014-04-04 10:13:25 +02:00
|
|
|
|
2012-06-14 13:06:06 +00:00
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// Changes endianness
|
2014-04-04 10:13:25 +02:00
|
|
|
inline UInt64 HostToNetwork8(const void * a_Value)
|
2012-06-14 13:06:06 +00:00
|
|
|
{
|
2015-03-17 20:00:21 +01:00
|
|
|
UInt64 buf;
|
2015-03-17 18:22:27 +01:00
|
|
|
memcpy( &buf, a_Value, sizeof( buf));
|
2015-07-09 11:15:37 -06:00
|
|
|
buf = (( ( static_cast<UInt64>(htonl(static_cast<UInt32>(buf)))) << 32) + htonl(buf >> 32));
|
2015-03-17 18:22:27 +01:00
|
|
|
return buf;
|
2012-06-14 13:06:06 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
2015-05-09 11:16:56 +02:00
|
|
|
inline UInt32 HostToNetwork4(const void * a_Value)
|
2012-06-14 13:06:06 +00:00
|
|
|
{
|
2015-03-17 20:00:21 +01:00
|
|
|
UInt32 buf;
|
2015-03-17 18:22:27 +01:00
|
|
|
memcpy( &buf, a_Value, sizeof( buf));
|
|
|
|
buf = ntohl( buf);
|
|
|
|
return buf;
|
2012-06-14 13:06:06 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
2014-04-04 10:13:25 +02:00
|
|
|
inline double NetworkToHostDouble8(const void * a_Value)
|
2012-06-14 13:06:06 +00:00
|
|
|
{
|
2014-04-04 10:13:25 +02:00
|
|
|
UInt64 buf = 0;
|
|
|
|
memcpy(&buf, a_Value, 8);
|
2012-06-14 13:06:06 +00:00
|
|
|
buf = ntohll(buf);
|
|
|
|
double x;
|
|
|
|
memcpy(&x, &buf, sizeof(double));
|
|
|
|
return x;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
2014-04-04 10:13:25 +02:00
|
|
|
inline Int64 NetworkToHostLong8(const void * a_Value)
|
2012-06-14 13:06:06 +00:00
|
|
|
{
|
2014-04-04 10:13:25 +02:00
|
|
|
UInt64 buf;
|
2014-04-05 22:34:05 +02:00
|
|
|
memcpy(&buf, a_Value, 8);
|
2012-06-14 13:06:06 +00:00
|
|
|
buf = ntohll(buf);
|
2014-04-04 10:13:25 +02:00
|
|
|
return *reinterpret_cast<Int64 *>(&buf);
|
2012-06-14 13:06:06 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
2015-03-21 13:00:20 +01:00
|
|
|
inline UInt64 NetworkToHostULong8(const void * a_Value)
|
|
|
|
{
|
|
|
|
UInt64 buf;
|
|
|
|
memcpy(&buf, a_Value, 8);
|
|
|
|
buf = ntohll(buf);
|
|
|
|
return buf;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
2014-04-04 10:13:25 +02:00
|
|
|
inline float NetworkToHostFloat4(const void * a_Value)
|
2012-06-14 13:06:06 +00:00
|
|
|
{
|
2014-04-04 10:13:25 +02:00
|
|
|
UInt32 buf;
|
|
|
|
float x;
|
2014-04-05 22:34:05 +02:00
|
|
|
memcpy(&buf, a_Value, 4);
|
2014-04-04 10:13:25 +02:00
|
|
|
buf = ntohl(buf);
|
|
|
|
memcpy(&x, &buf, sizeof(float));
|
2012-06-14 13:06:06 +00:00
|
|
|
return x;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|