From 0a779bd791fb63b2fc1663206279c7eaa9c02c6f Mon Sep 17 00:00:00 2001 From: Shauren Date: Thu, 4 Oct 2018 18:50:21 +0200 Subject: Core/PacketIO: Updated packet structures to 8.0.1 --- src/server/shared/Packets/ByteBuffer.h | 23 +++++++++++++++++------ 1 file changed, 17 insertions(+), 6 deletions(-) (limited to 'src/server/shared/Packets') diff --git a/src/server/shared/Packets/ByteBuffer.h b/src/server/shared/Packets/ByteBuffer.h index fdd3667a3a6..c7009028e9c 100644 --- a/src/server/shared/Packets/ByteBuffer.h +++ b/src/server/shared/Packets/ByteBuffer.h @@ -123,9 +123,10 @@ class TC_SHARED_API ByteBuffer _storage.clear(); } - template void append(T value) + template + void append(T value) { - static_assert(std::is_fundamental::value, "append(compound)"); + static_assert(std::is_trivially_copyable::value, "append(T) must be used with trivially copyable types"); EndianConvert(value); append((uint8 *)&value, sizeof(value)); } @@ -210,7 +211,7 @@ class TC_SHARED_API ByteBuffer template void put(std::size_t pos, T value) { - static_assert(std::is_fundamental::value, "append(compound)"); + static_assert(std::is_trivially_copyable::value, "put(size_t, T) must be used with trivially copyable types"); EndianConvert(value); put(pos, (uint8 *)&value, sizeof(value)); } @@ -435,7 +436,8 @@ class TC_SHARED_API ByteBuffer _rpos += skip; } - template T read() + template + T read() { ResetBitPos(); T r = read(_rpos); @@ -443,7 +445,8 @@ class TC_SHARED_API ByteBuffer return r; } - template T read(size_t pos) const + template + T read(size_t pos) const { if (pos + sizeof(T) > size()) throw ByteBufferPositionException(pos, sizeof(T), size()); @@ -452,6 +455,13 @@ class TC_SHARED_API ByteBuffer return val; } + template + void read(T* dest, size_t count) + { + static_assert(std::is_trivially_copyable::value, "read(T*, size_t) must be used with trivially copyable types"); + return read(reinterpret_cast(dest), count * sizeof(T)); + } + void read(uint8 *dest, size_t len) { if (_rpos + len > size()) @@ -540,7 +550,8 @@ class TC_SHARED_API ByteBuffer return append((const uint8 *)src, cnt); } - template void append(const T *src, size_t cnt) + template + void append(const T *src, size_t cnt) { return append((const uint8 *)src, cnt * sizeof(T)); } -- cgit v1.2.3