diff options
author | Tycho <work.tycho+git@gmail.com> | 2014-04-27 15:35:27 +0200 |
---|---|---|
committer | Tycho <work.tycho+git@gmail.com> | 2014-04-27 15:35:27 +0200 |
commit | 57b8ee9163181920b634e475c781fe7764e11b98 (patch) | |
tree | 7d0675f8cda49a39b0b42eaaa928cfb66b57869a /src/Endianness.h | |
parent | Implemented Chunk Sparsing with segments (diff) | |
parent | Merge pull request #863 from mc-server/chunkysparsing (diff) | |
download | cuberite-57b8ee9163181920b634e475c781fe7764e11b98.tar cuberite-57b8ee9163181920b634e475c781fe7764e11b98.tar.gz cuberite-57b8ee9163181920b634e475c781fe7764e11b98.tar.bz2 cuberite-57b8ee9163181920b634e475c781fe7764e11b98.tar.lz cuberite-57b8ee9163181920b634e475c781fe7764e11b98.tar.xz cuberite-57b8ee9163181920b634e475c781fe7764e11b98.tar.zst cuberite-57b8ee9163181920b634e475c781fe7764e11b98.zip |
Diffstat (limited to 'src/Endianness.h')
-rw-r--r-- | src/Endianness.h | 31 |
1 files changed, 17 insertions, 14 deletions
diff --git a/src/Endianness.h b/src/Endianness.h index 86eb369f5..78f9a5d99 100644 --- a/src/Endianness.h +++ b/src/Endianness.h @@ -1,12 +1,14 @@ #pragma once +#define ntohll(x) ((((UInt64)ntohl((u_long)x)) << 32) + ntohl(x >> 32)) + // Changes endianness -inline unsigned long long HostToNetwork8(const void* a_Value ) +inline UInt64 HostToNetwork8(const void * a_Value) { unsigned long long __HostToNetwork8; memcpy( &__HostToNetwork8, a_Value, sizeof( __HostToNetwork8 ) ); @@ -18,7 +20,7 @@ inline unsigned long long HostToNetwork8(const void* a_Value ) -inline unsigned int HostToNetwork4(const void* a_Value ) +inline UInt32 HostToNetwork4(const void* a_Value ) { unsigned int __HostToNetwork4; memcpy( &__HostToNetwork4, a_Value, sizeof( __HostToNetwork4 ) ); @@ -30,11 +32,10 @@ inline unsigned int HostToNetwork4(const void* a_Value ) -inline double NetworkToHostDouble8(const void* a_Value ) +inline double NetworkToHostDouble8(const void * a_Value) { -#define ntohll(x) ((((unsigned long long)ntohl((u_long)x)) << 32) + ntohl(x >> 32)) - unsigned long long buf = 0;//(*(unsigned long long*)a_Value); - memcpy( &buf, a_Value, 8 ); + UInt64 buf = 0; + memcpy(&buf, a_Value, 8); buf = ntohll(buf); double x; memcpy(&x, &buf, sizeof(double)); @@ -45,23 +46,25 @@ inline double NetworkToHostDouble8(const void* a_Value ) -inline long long NetworkToHostLong8(const void * a_Value ) +inline Int64 NetworkToHostLong8(const void * a_Value) { - unsigned long long buf = *(unsigned long long*)a_Value; + UInt64 buf; + memcpy(&buf, a_Value, 8); buf = ntohll(buf); - return *reinterpret_cast<long long *>(&buf); + return *reinterpret_cast<Int64 *>(&buf); } -inline float NetworkToHostFloat4(const void* a_Value ) +inline float NetworkToHostFloat4(const void * a_Value) { - u_long buf = *(u_long*)a_Value; - buf = ntohl( buf ); - float x = 0; - memcpy( &x, &buf, sizeof(float) ); + UInt32 buf; + float x; + memcpy(&buf, a_Value, 4); + buf = ntohl(buf); + memcpy(&x, &buf, sizeof(float)); return x; } |