summaryrefslogtreecommitdiffstats
path: root/source/ByteBuffer.cpp
diff options
context:
space:
mode:
authormadmaxoft <github@xoft.cz>2013-11-24 14:35:35 +0100
committermadmaxoft <github@xoft.cz>2013-11-24 14:35:35 +0100
commitdbb76ef9fefa90a1e24acc42ba0421980df89379 (patch)
treea1e980d5d55a5aa0ca250d247e760e120c3bf1e5 /source/ByteBuffer.cpp
parentRCON server: Login failure gets sent to the client. (diff)
downloadcuberite-dbb76ef9fefa90a1e24acc42ba0421980df89379.tar
cuberite-dbb76ef9fefa90a1e24acc42ba0421980df89379.tar.gz
cuberite-dbb76ef9fefa90a1e24acc42ba0421980df89379.tar.bz2
cuberite-dbb76ef9fefa90a1e24acc42ba0421980df89379.tar.lz
cuberite-dbb76ef9fefa90a1e24acc42ba0421980df89379.tar.xz
cuberite-dbb76ef9fefa90a1e24acc42ba0421980df89379.tar.zst
cuberite-dbb76ef9fefa90a1e24acc42ba0421980df89379.zip
Diffstat (limited to 'source/ByteBuffer.cpp')
-rw-r--r--source/ByteBuffer.cpp54
1 files changed, 54 insertions, 0 deletions
diff --git a/source/ByteBuffer.cpp b/source/ByteBuffer.cpp
index 1cdd2f430..8f2b76c1f 100644
--- a/source/ByteBuffer.cpp
+++ b/source/ByteBuffer.cpp
@@ -13,6 +13,25 @@
+// Try to determine endianness:
+#if ( \
+ defined(__i386__) || defined(__alpha__) || \
+ defined(__ia64) || defined(__ia64__) || \
+ defined(_M_IX86) || defined(_M_IA64) || \
+ defined(_M_ALPHA) || defined(__amd64) || \
+ defined(__amd64__) || defined(_M_AMD64) || \
+ defined(__x86_64) || defined(__x86_64__) || \
+ defined(_M_X64) || defined(__bfin__) || \
+ defined(__ARMEL__) || \
+ (defined(_WIN32) && defined(__ARM__) && defined(_MSC_VER)) \
+)
+ #define IS_LITTLE_ENDIAN
+#elif defined (__ARMEB__)
+ #define IS_BIG_ENDIAN
+#else
+ #error Cannot determine endianness of this platform
+#endif
+
// If a string sent over the protocol is larger than this, a warning is emitted to the console
#define MAX_STRING_SIZE (512 KiB)
@@ -416,6 +435,25 @@ bool cByteBuffer::ReadVarUTF8String(AString & a_Value)
+bool cByteBuffer::ReadLEInt(int & a_Value)
+{
+ CHECK_THREAD;
+ CheckValid();
+ NEEDBYTES(4);
+ ReadBuf(&a_Value, 4);
+
+ #ifdef IS_BIG_ENDIAN
+ // Convert:
+ a_Value = ((a_Value >> 24) & 0xff) | ((a_Value >> 16) & 0xff00) | ((a_Value >> 8) & 0xff0000) | (a_Value & 0xff000000);
+ #endif
+
+ return true;
+}
+
+
+
+
+
bool cByteBuffer::WriteChar(char a_Value)
{
CHECK_THREAD;
@@ -572,6 +610,22 @@ bool cByteBuffer::WriteVarUTF8String(const AString & a_Value)
+bool cByteBuffer::WriteLEInt(int a_Value)
+{
+ CHECK_THREAD;
+ CheckValid();
+ #ifdef IS_LITTLE_ENDIAN
+ return WriteBuf((const char *)&a_Value, 4);
+ #else
+ int Value = ((a_Value >> 24) & 0xff) | ((a_Value >> 16) & 0xff00) | ((a_Value >> 8) & 0xff0000) | (a_Value & 0xff000000);
+ return WriteBuf((const char *)&Value, 4);
+ #endif
+}
+
+
+
+
+
bool cByteBuffer::ReadBuf(void * a_Buffer, int a_Count)
{
CHECK_THREAD;