summaryrefslogtreecommitdiffstats
path: root/src/Endianness.h
diff options
context:
space:
mode:
authorMattes D <github@xoft.cz>2013-11-27 09:23:17 +0100
committerMattes D <github@xoft.cz>2013-11-27 09:23:17 +0100
commit49760db89d94ede5d123d927141a6cd60dbaaf07 (patch)
tree6c6cf99e4cf3128311a93cd187947b502f3732a0 /src/Endianness.h
parentcWorld::SpawnExperienceOrb() now returns the entity ID of the spawned orb. (diff)
parentFixed VC2008 compilation, normalized include paths. (diff)
downloadcuberite-49760db89d94ede5d123d927141a6cd60dbaaf07.tar
cuberite-49760db89d94ede5d123d927141a6cd60dbaaf07.tar.gz
cuberite-49760db89d94ede5d123d927141a6cd60dbaaf07.tar.bz2
cuberite-49760db89d94ede5d123d927141a6cd60dbaaf07.tar.lz
cuberite-49760db89d94ede5d123d927141a6cd60dbaaf07.tar.xz
cuberite-49760db89d94ede5d123d927141a6cd60dbaaf07.tar.zst
cuberite-49760db89d94ede5d123d927141a6cd60dbaaf07.zip
Diffstat (limited to 'src/Endianness.h')
-rw-r--r--src/Endianness.h70
1 files changed, 70 insertions, 0 deletions
diff --git a/src/Endianness.h b/src/Endianness.h
new file mode 100644
index 000000000..86eb369f5
--- /dev/null
+++ b/src/Endianness.h
@@ -0,0 +1,70 @@
+
+#pragma once
+
+
+
+
+
+// Changes endianness
+inline unsigned long long 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 unsigned int 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 )
+{
+#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 );
+ buf = ntohll(buf);
+ double x;
+ memcpy(&x, &buf, sizeof(double));
+ return x;
+}
+
+
+
+
+
+inline long long NetworkToHostLong8(const void * a_Value )
+{
+ unsigned long long buf = *(unsigned long long*)a_Value;
+ buf = ntohll(buf);
+ return *reinterpret_cast<long long *>(&buf);
+}
+
+
+
+
+
+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) );
+ return x;
+}
+
+
+
+