diff options
author | Tiger Wang <ziwei.tiger@hotmail.co.uk> | 2013-11-24 15:55:08 +0100 |
---|---|---|
committer | Tiger Wang <ziwei.tiger@hotmail.co.uk> | 2013-11-24 15:55:08 +0100 |
commit | f95064a85c83e1a77a5de2f8a09e5907573f8277 (patch) | |
tree | 9896aa6cff228acbc0b188b6c37e2032152fe661 /source/ByteBuffer.cpp | |
parent | Fixed some comments and added debug logging (diff) | |
parent | RCONClient: Initial implementation. (diff) | |
download | cuberite-f95064a85c83e1a77a5de2f8a09e5907573f8277.tar cuberite-f95064a85c83e1a77a5de2f8a09e5907573f8277.tar.gz cuberite-f95064a85c83e1a77a5de2f8a09e5907573f8277.tar.bz2 cuberite-f95064a85c83e1a77a5de2f8a09e5907573f8277.tar.lz cuberite-f95064a85c83e1a77a5de2f8a09e5907573f8277.tar.xz cuberite-f95064a85c83e1a77a5de2f8a09e5907573f8277.tar.zst cuberite-f95064a85c83e1a77a5de2f8a09e5907573f8277.zip |
Diffstat (limited to 'source/ByteBuffer.cpp')
-rw-r--r-- | source/ByteBuffer.cpp | 54 |
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; |