Core/Misc: Add extra ByteBuffer and WorldPacket constructors allowing to set size immediately

This commit is contained in:
Shauren
2020-05-20 17:28:38 +02:00
parent 4acae3992b
commit aedab76a11
5 changed files with 32 additions and 20 deletions

View File

@@ -30,7 +30,7 @@ class MessageBuffer;
class TC_SHARED_API ByteBufferException : public std::exception
{
public:
~ByteBufferException() noexcept { }
~ByteBufferException() noexcept = default;
char const* what() const noexcept override { return msg_.c_str(); }
@@ -46,7 +46,7 @@ class TC_SHARED_API ByteBufferPositionException : public ByteBufferException
public:
ByteBufferPositionException(size_t pos, size_t size, size_t valueSize);
~ByteBufferPositionException() noexcept { }
~ByteBufferPositionException() noexcept = default;
};
class TC_SHARED_API ByteBuffer
@@ -61,16 +61,24 @@ class TC_SHARED_API ByteBuffer
_storage.reserve(DEFAULT_SIZE);
}
ByteBuffer(size_t reserve) : _rpos(0), _wpos(0), _bitpos(InitialBitPos), _curbitval(0)
// reserve/resize tag
struct Reserve { };
struct Resize { };
ByteBuffer(size_t size, Reserve) : _rpos(0), _wpos(0), _bitpos(InitialBitPos), _curbitval(0)
{
_storage.reserve(reserve);
_storage.reserve(size);
}
ByteBuffer(size_t size, Resize) : _rpos(0), _wpos(size), _bitpos(InitialBitPos), _curbitval(0)
{
_storage.resize(size);
}
ByteBuffer(ByteBuffer&& buf) noexcept : _rpos(buf._rpos), _wpos(buf._wpos),
_bitpos(buf._bitpos), _curbitval(buf._curbitval), _storage(buf.Move()) { }
ByteBuffer(ByteBuffer const& right) : _rpos(right._rpos), _wpos(right._wpos),
_bitpos(right._bitpos), _curbitval(right._curbitval), _storage(right._storage) { }
ByteBuffer(ByteBuffer const& right) = default;
ByteBuffer(MessageBuffer&& buffer);
@@ -111,7 +119,7 @@ class TC_SHARED_API ByteBuffer
return *this;
}
virtual ~ByteBuffer() { }
virtual ~ByteBuffer() = default;
void clear()
{