mirror of
https://github.com/TrinityCore/TrinityCore.git
synced 2026-01-15 23:20:36 +01:00
Core/PacketIO: Improved bit functions - no longer reads each bit separately
This commit is contained in:
@@ -17,18 +17,14 @@
|
||||
|
||||
#include "ByteBuffer.h"
|
||||
#include "Errors.h"
|
||||
#include "MessageBuffer.h"
|
||||
#include "Log.h"
|
||||
#include "MessageBuffer.h"
|
||||
#include "Util.h"
|
||||
#include <utf8.h>
|
||||
#include <algorithm>
|
||||
#include <sstream>
|
||||
#include <cmath>
|
||||
|
||||
ByteBuffer::ByteBuffer(MessageBuffer&& buffer) : _rpos(0), _wpos(0), _bitpos(InitialBitPos), _curbitval(0), _storage(buffer.Move())
|
||||
{
|
||||
}
|
||||
|
||||
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))
|
||||
{
|
||||
@@ -39,6 +35,10 @@ ByteBufferInvalidValueException::ByteBufferInvalidValueException(char const* typ
|
||||
{
|
||||
}
|
||||
|
||||
ByteBuffer::ByteBuffer(MessageBuffer&& buffer) : _rpos(0), _wpos(0), _bitpos(InitialBitPos), _curbitval(0), _storage(buffer.Move())
|
||||
{
|
||||
}
|
||||
|
||||
ByteBuffer& ByteBuffer::operator>>(float& value)
|
||||
{
|
||||
read(&value, 1);
|
||||
@@ -145,63 +145,67 @@ void ByteBuffer::PutBits(std::size_t pos, std::size_t value, uint32 bitCount)
|
||||
|
||||
void ByteBuffer::print_storage() const
|
||||
{
|
||||
if (!sLog->ShouldLog("network", LOG_LEVEL_TRACE)) // optimize disabled trace output
|
||||
Logger const* networkLogger = sLog->GetEnabledLogger("network", LOG_LEVEL_TRACE);
|
||||
if (!networkLogger) // optimize disabled trace output
|
||||
return;
|
||||
|
||||
std::ostringstream o;
|
||||
o << "STORAGE_SIZE: " << size();
|
||||
for (uint32 i = 0; i < size(); ++i)
|
||||
o << read<uint8>(i) << " - ";
|
||||
o << ' ';
|
||||
o << uint32(_storage[i]) << " - ";
|
||||
|
||||
TC_LOG_TRACE("network", "{}", o.str());
|
||||
TC_LOG_TRACE("network", "STORAGE_SIZE: {} {}", size(), o.view());
|
||||
}
|
||||
|
||||
void ByteBuffer::textlike() const
|
||||
{
|
||||
if (!sLog->ShouldLog("network", LOG_LEVEL_TRACE)) // optimize disabled trace output
|
||||
Logger const* networkLogger = sLog->GetEnabledLogger("network", LOG_LEVEL_TRACE);
|
||||
if (networkLogger) // optimize disabled trace output
|
||||
return;
|
||||
|
||||
std::ostringstream o;
|
||||
o << "STORAGE_SIZE: " << size();
|
||||
for (uint32 i = 0; i < size(); ++i)
|
||||
{
|
||||
char buf[2];
|
||||
snprintf(buf, 2, "%c", read<uint8>(i));
|
||||
o << buf;
|
||||
}
|
||||
o << ' ';
|
||||
TC_LOG_TRACE("network", "{}", o.str());
|
||||
o << char(_storage[i]);
|
||||
|
||||
sLog->OutMessageTo(networkLogger, "network", LOG_LEVEL_TRACE, "STORAGE_SIZE: {} {}", size(), o.view());
|
||||
}
|
||||
|
||||
void ByteBuffer::hexlike() const
|
||||
{
|
||||
if (!sLog->ShouldLog("network", LOG_LEVEL_TRACE)) // optimize disabled trace output
|
||||
Logger const* networkLogger = sLog->GetEnabledLogger("network", LOG_LEVEL_TRACE);
|
||||
if (!networkLogger) // optimize disabled trace output
|
||||
return;
|
||||
|
||||
uint32 j = 1, k = 1;
|
||||
|
||||
std::ostringstream o;
|
||||
o << "STORAGE_SIZE: " << size();
|
||||
o.setf(std::ios_base::hex, std::ios_base::basefield);
|
||||
o.fill('0');
|
||||
|
||||
for (uint32 i = 0; i < size(); ++i)
|
||||
for (uint32 i = 0; i < size(); )
|
||||
{
|
||||
char buf[4];
|
||||
snprintf(buf, 4, "%02X", read<uint8>(i));
|
||||
if ((i == (j * 8)) && ((i != (k * 16))))
|
||||
char const* sep = " | ";
|
||||
for (uint32 j = 0; j < 2; ++j)
|
||||
{
|
||||
o << "| ";
|
||||
++j;
|
||||
}
|
||||
else if (i == (k * 16))
|
||||
{
|
||||
o << '\n';
|
||||
++k;
|
||||
++j;
|
||||
}
|
||||
for (uint32 k = 0; k < 8; ++k)
|
||||
{
|
||||
o.width(2);
|
||||
o << _storage[i];
|
||||
++i;
|
||||
}
|
||||
|
||||
o << buf;
|
||||
o << sep;
|
||||
sep = "\n";
|
||||
}
|
||||
}
|
||||
o << ' ';
|
||||
TC_LOG_TRACE("network", "{}", o.str());
|
||||
|
||||
sLog->OutMessageTo(networkLogger, "network", LOG_LEVEL_TRACE, "STORAGE_SIZE: {} {}", size(), o.view());
|
||||
}
|
||||
|
||||
template TC_SHARED_API uint8 ByteBuffer::read<uint8>();
|
||||
template TC_SHARED_API uint16 ByteBuffer::read<uint16>();
|
||||
template TC_SHARED_API uint32 ByteBuffer::read<uint32>();
|
||||
template TC_SHARED_API uint64 ByteBuffer::read<uint64>();
|
||||
template TC_SHARED_API int8 ByteBuffer::read<int8>();
|
||||
template TC_SHARED_API int16 ByteBuffer::read<int16>();
|
||||
template TC_SHARED_API int32 ByteBuffer::read<int32>();
|
||||
template TC_SHARED_API int64 ByteBuffer::read<int64>();
|
||||
template TC_SHARED_API float ByteBuffer::read<float>();
|
||||
template TC_SHARED_API double ByteBuffer::read<double>();
|
||||
|
||||
Reference in New Issue
Block a user