diff options
-rw-r--r-- | src/server/shared/Packets/ByteBuffer.cpp | 20 | ||||
-rw-r--r-- | src/server/shared/Packets/ByteBuffer.h | 10 |
2 files changed, 9 insertions, 21 deletions
diff --git a/src/server/shared/Packets/ByteBuffer.cpp b/src/server/shared/Packets/ByteBuffer.cpp index 8718a31d829..07a21a3e73a 100644 --- a/src/server/shared/Packets/ByteBuffer.cpp +++ b/src/server/shared/Packets/ByteBuffer.cpp @@ -29,19 +29,13 @@ ByteBuffer::ByteBuffer(MessageBuffer&& buffer) : _rpos(0), _wpos(0), _bitpos(Ini } ByteBufferPositionException::ByteBufferPositionException(size_t pos, size_t size, size_t valueSize) + : ByteBufferException(Trinity::StringFormat("Attempted to get value with size: {} in ByteBuffer (pos: {} size: {})", valueSize, pos, size)) { - std::ostringstream ss; - - ss << "Attempted to get value with size: " - << valueSize << " in ByteBuffer (pos: " << pos << " size: " << size - << ")"; - - message().assign(ss.str()); } ByteBufferInvalidValueException::ByteBufferInvalidValueException(char const* type, char const* value) + : ByteBufferException(Trinity::StringFormat("Invalid {} value ({}) found in ByteBuffer", type, value)) { - message().assign(Trinity::StringFormat("Invalid {} value ({}) found in ByteBuffer", type, value)); } ByteBuffer& ByteBuffer::operator>>(float& value) @@ -152,7 +146,7 @@ void ByteBuffer::print_storage() const o << "STORAGE_SIZE: " << size(); for (uint32 i = 0; i < size(); ++i) o << read<uint8>(i) << " - "; - o << " "; + o << ' '; TC_LOG_TRACE("network", "{}", o.str()); } @@ -170,7 +164,7 @@ void ByteBuffer::textlike() const snprintf(buf, 2, "%c", read<uint8>(i)); o << buf; } - o << " "; + o << ' '; TC_LOG_TRACE("network", "{}", o.str()); } @@ -187,7 +181,7 @@ void ByteBuffer::hexlike() const for (uint32 i = 0; i < size(); ++i) { char buf[4]; - snprintf(buf, 4, "%2X", read<uint8>(i)); + snprintf(buf, 4, "%02X", read<uint8>(i)); if ((i == (j * 8)) && ((i != (k * 16)))) { o << "| "; @@ -195,13 +189,13 @@ void ByteBuffer::hexlike() const } else if (i == (k * 16)) { - o << "\n"; + o << '\n'; ++k; ++j; } o << buf; } - o << " "; + o << ' '; TC_LOG_TRACE("network", "{}", o.str()); } diff --git a/src/server/shared/Packets/ByteBuffer.h b/src/server/shared/Packets/ByteBuffer.h index de0adf54341..7de0dde99e7 100644 --- a/src/server/shared/Packets/ByteBuffer.h +++ b/src/server/shared/Packets/ByteBuffer.h @@ -31,14 +31,12 @@ class MessageBuffer; class TC_SHARED_API ByteBufferException : public std::exception { public: - ~ByteBufferException() noexcept = default; + explicit ByteBufferException() = default; + explicit ByteBufferException(std::string&& message) noexcept : msg_(std::move(message)) { } char const* what() const noexcept override { return msg_.c_str(); } protected: - std::string & message() noexcept { return msg_; } - -private: std::string msg_; }; @@ -46,16 +44,12 @@ class TC_SHARED_API ByteBufferPositionException : public ByteBufferException { public: ByteBufferPositionException(size_t pos, size_t size, size_t valueSize); - - ~ByteBufferPositionException() noexcept = default; }; class TC_SHARED_API ByteBufferInvalidValueException : public ByteBufferException { public: ByteBufferInvalidValueException(char const* type, char const* value); - - ~ByteBufferInvalidValueException() noexcept = default; }; class TC_SHARED_API ByteBuffer |