diff options
author | madmaxoft <github@xoft.cz> | 2013-10-28 20:40:42 +0100 |
---|---|---|
committer | madmaxoft <github@xoft.cz> | 2013-10-28 20:40:55 +0100 |
commit | c9b6c3bc2e3b6e9c06d7cd43345565bc88bb30f9 (patch) | |
tree | 7a9cf8dcf32a51fbbc6efbe4800d3854dbee3b25 /source/ByteBuffer.h | |
parent | Fixed indentation in tonibm19's code. (diff) | |
download | cuberite-c9b6c3bc2e3b6e9c06d7cd43345565bc88bb30f9.tar cuberite-c9b6c3bc2e3b6e9c06d7cd43345565bc88bb30f9.tar.gz cuberite-c9b6c3bc2e3b6e9c06d7cd43345565bc88bb30f9.tar.bz2 cuberite-c9b6c3bc2e3b6e9c06d7cd43345565bc88bb30f9.tar.lz cuberite-c9b6c3bc2e3b6e9c06d7cd43345565bc88bb30f9.tar.xz cuberite-c9b6c3bc2e3b6e9c06d7cd43345565bc88bb30f9.tar.zst cuberite-c9b6c3bc2e3b6e9c06d7cd43345565bc88bb30f9.zip |
Diffstat (limited to 'source/ByteBuffer.h')
-rw-r--r-- | source/ByteBuffer.h | 22 |
1 files changed, 19 insertions, 3 deletions
diff --git a/source/ByteBuffer.h b/source/ByteBuffer.h index 650eda5b0..eb5ce5910 100644 --- a/source/ByteBuffer.h +++ b/source/ByteBuffer.h @@ -57,8 +57,22 @@ public: bool ReadBEFloat (float & a_Value); bool ReadBEDouble (double & a_Value); bool ReadBool (bool & a_Value); - bool ReadBEUTF16String16(AString & a_Value); - + bool ReadBEUTF16String16(AString & a_Value); // string length as BE short, then string as UTF-16BE + bool ReadVarInt (UInt64 & a_Value); + bool ReadVarUTF8String (AString & a_Value); // string length as VarInt, then string as UTF-8 + + /// Reads VarInt, assigns it to anything that can be assigned from an UInt64 (unsigned int, short, char, Byte, double, ...) + template <typename T> bool ReadVarUInt(T & a_Value) + { + UInt64 v; + bool res = ReadVarInt(v); + if (res) + { + a_Value = v; + } + return res; + } + // Write the specified datatype; return true if successfully written bool WriteChar (char a_Value); bool WriteByte (unsigned char a_Value); @@ -68,7 +82,9 @@ public: bool WriteBEFloat (float a_Value); bool WriteBEDouble (double a_Value); bool WriteBool (bool a_Value); - bool WriteBEUTF16String16(const AString & a_Value); + bool WriteBEUTF16String16(const AString & a_Value); // string length as BE short, then string as UTF-16BE + bool WriteVarInt (UInt64 a_Value); + bool WriteVarUTF8String (AString & a_Value); // string length as VarInt, then string as UTF-8 /// Reads a_Count bytes into a_Buffer; returns true if successful bool ReadBuf(void * a_Buffer, int a_Count); |