1
0

ByteBuffer: Added support for reading unsigned shorts and ints.

This commit is contained in:
Matyas Dolak 2015-01-21 12:12:22 +01:00
parent b333551830
commit adf3b3a569
2 changed files with 33 additions and 1 deletions

View File

@ -344,12 +344,28 @@ bool cByteBuffer::ReadByte(unsigned char & a_Value)
bool cByteBuffer::ReadBEShort(short & a_Value) bool cByteBuffer::ReadBEShort(short & a_Value)
{
CHECK_THREAD
CheckValid();
NEEDBYTES(2);
Int16 val;
ReadBuf(&val, 2);
val = ntohs(val);
a_Value = *(reinterpret_cast<short *>(&val));
return true;
}
bool cByteBuffer::ReadBEUInt16(UInt16 & a_Value)
{ {
CHECK_THREAD CHECK_THREAD
CheckValid(); CheckValid();
NEEDBYTES(2); NEEDBYTES(2);
ReadBuf(&a_Value, 2); ReadBuf(&a_Value, 2);
a_Value = (short)ntohs((u_short)a_Value); a_Value = ntohs(a_Value);
return true; return true;
} }
@ -371,6 +387,20 @@ bool cByteBuffer::ReadBEInt(int & a_Value)
bool cByteBuffer::ReadBEUInt32(UInt32 & a_Value)
{
CHECK_THREAD
CheckValid();
NEEDBYTES(4);
ReadBuf(&a_Value, 4);
a_Value = ntohl(a_Value);
return true;
}
bool cByteBuffer::ReadBEInt64(Int64 & a_Value) bool cByteBuffer::ReadBEInt64(Int64 & a_Value)
{ {
CHECK_THREAD CHECK_THREAD

View File

@ -55,7 +55,9 @@ public:
bool ReadChar (char & a_Value); bool ReadChar (char & a_Value);
bool ReadByte (unsigned char & a_Value); bool ReadByte (unsigned char & a_Value);
bool ReadBEShort (short & a_Value); bool ReadBEShort (short & a_Value);
bool ReadBEUInt16 (UInt16 & a_Value);
bool ReadBEInt (int & a_Value); bool ReadBEInt (int & a_Value);
bool ReadBEUInt32 (UInt32 & a_Value);
bool ReadBEInt64 (Int64 & a_Value); bool ReadBEInt64 (Int64 & a_Value);
bool ReadBEFloat (float & a_Value); bool ReadBEFloat (float & a_Value);
bool ReadBEDouble (double & a_Value); bool ReadBEDouble (double & a_Value);