aboutsummaryrefslogtreecommitdiff
path: root/src/server/shared
diff options
context:
space:
mode:
authorShauren <shauren.trinity@gmail.com>2014-10-23 17:01:26 +0200
committerShauren <shauren.trinity@gmail.com>2014-10-23 17:01:26 +0200
commit08c56eb1109aed2c6dabe728c945d4afd4943753 (patch)
tree27c73ebb9fcf30c3a7fd08fef6d58a6f4a585190 /src/server/shared
parentff781978a56b33567d704a860a94e5e28a53aee4 (diff)
Core/Entities: First step to 128 bit guids
* Database fields storing full guid have been converted to BINARY(16)
Diffstat (limited to 'src/server/shared')
-rw-r--r--src/server/shared/Packets/ByteBuffer.h65
1 files changed, 34 insertions, 31 deletions
diff --git a/src/server/shared/Packets/ByteBuffer.h b/src/server/shared/Packets/ByteBuffer.h
index de871c5e6df..13e96833c82 100644
--- a/src/server/shared/Packets/ByteBuffer.h
+++ b/src/server/shared/Packets/ByteBuffer.h
@@ -483,35 +483,24 @@ class ByteBuffer
_rpos += len;
}
- void readPackGUID(uint64& guid)
+ void ReadPackedUInt64(uint64& guid)
{
- if (rpos() + 1 > size())
- throw ByteBufferPositionException(false, _rpos, 1, size());
-
guid = 0;
+ ReadPackedUInt64(read<uint8>(), guid);
+ }
- uint8 guidmark = 0;
- (*this) >> guidmark;
-
- for (int i = 0; i < 8; ++i)
- {
- if (guidmark & (uint8(1) << i))
- {
- if (rpos() + 1 > size())
- throw ByteBufferPositionException(false, _rpos, 1, size());
-
- uint8 bit;
- (*this) >> bit;
- guid |= (uint64(bit) << (i * 8));
- }
- }
+ void ReadPackedUInt64(uint8 mask, uint64& value)
+ {
+ for (uint32 i = 0; i < 8; ++i)
+ if (mask & (uint8(1) << i))
+ value |= (uint64(read<uint8>()) << (i * 8));
}
std::string ReadString(uint32 length)
{
if (!length)
return std::string();
- char* buffer = new char[length + 1]();
+ char* buffer = new char[length + 1];
read((uint8*)buffer, length);
std::string retval = buffer;
delete[] buffer;
@@ -621,23 +610,37 @@ class ByteBuffer
*this << packed;
}
- void appendPackGUID(uint64 guid)
+ void AppendPackedUInt64(uint64 guid)
+ {
+ uint8 mask = 0;
+ size_t pos = wpos();
+ *this << uint8(mask);
+
+ uint8 packed[8];
+ if (size_t packedSize = PackUInt64(guid, &mask, packed))
+ append(packed, packedSize);
+
+ put<uint8>(pos, mask);
+ }
+
+ size_t PackUInt64(uint64 value, uint8* mask, uint8* result) const
{
- uint8 packGUID[8+1];
- packGUID[0] = 0;
- size_t size = 1;
- for (uint8 i = 0;guid != 0;++i)
+ size_t resultSize = 0;
+ *mask = 0;
+ memset(result, 0, 8);
+
+ for (uint8 i = 0; value != 0; ++i)
{
- if (guid & 0xFF)
+ if (value & 0xFF)
{
- packGUID[0] |= uint8(1 << i);
- packGUID[size] = uint8(guid & 0xFF);
- ++size;
+ *mask |= uint8(1 << i);
+ result[resultSize++] = uint8(value & 0xFF);
}
- guid >>= 8;
+ value >>= 8;
}
- append(packGUID, size);
+
+ return resultSize;
}
void AppendPackedTime(time_t time)