diff --git a/src/shared/ByteBuffer.cpp b/src/shared/ByteBuffer.cpp index 3254d97c8..34e16d3a1 100644 --- a/src/shared/ByteBuffer.cpp +++ b/src/shared/ByteBuffer.cpp @@ -17,95 +17,61 @@ */ #include "ByteBuffer.h" -#include "Log.h" -void ByteBufferException::PrintPosError() const +void BitStream::Clear() { - char const* traceStr; - -#ifdef HAVE_ACE_STACK_TRACE_H - ACE_Stack_Trace trace; - traceStr = trace.c_str(); -#else - traceStr = NULL; -#endif - - sLog.outError( - "Attempted to %s in ByteBuffer (pos: " SIZEFMTD " size: " SIZEFMTD ") " - "value with size: " SIZEFMTD "%s%s", - (add ? "put" : "get"), pos, size, esize, - traceStr ? "\n" : "", traceStr ? traceStr : ""); + _data.clear(); + _rpos = _wpos = 0; } -void ByteBuffer::print_storage() const +uint8 BitStream::GetBit(uint32 bit) { - if (!sLog.HasLogLevelOrHigher(LOG_LVL_DEBUG)) // optimize disabled debug output - return; + MANGOS_ASSERT(_data.size() > bit); + return _data[bit]; +} - std::ostringstream ss; - ss << "STORAGE_SIZE: " << size() << "\n"; +uint8 BitStream::ReadBit() +{ + MANGOS_ASSERT(_data.size() < _rpos); + uint8 b = _data[_rpos]; + ++_rpos; + return b; +} - if (sLog.IsIncludeTime()) - ss << " "; +void BitStream::WriteBit(uint32 bit) +{ + _data.push_back(bit ? uint8(1) : uint8(0)); + ++_wpos; +} - for (size_t i = 0; i < size(); ++i) - ss << uint32(read(i)) << " - "; +template void BitStream::WriteBits(T value, size_t bits) +{ + for (int32 i = bits-1; i >= 0; --i) + WriteBit((value >> i) & 1); +} + +bool BitStream::Empty() +{ + return _data.empty(); +} + +void BitStream::Reverse() +{ + uint32 len = GetLength(); + std::vector b = _data; + Clear(); + + for(uint32 i = len; i > 0; --i) + WriteBit(b[i-1]); +} + +void BitStream::Print() +{ + std::stringstream ss; + ss << "BitStream: "; + for (uint32 i = 0; i < GetLength(); ++i) + ss << uint32(GetBit(i)) << " "; sLog.outDebug(ss.str().c_str()); } -void ByteBuffer::textlike() const -{ - if (!sLog.HasLogLevelOrHigher(LOG_LVL_DEBUG)) // optimize disabled debug output - return; - - std::ostringstream ss; - ss << "STORAGE_SIZE: " << size() << "\n"; - - if (sLog.IsIncludeTime()) - ss << " "; - - for (size_t i = 0; i < size(); ++i) - ss << read(i); - - sLog.outDebug(ss.str().c_str()); -} - -void ByteBuffer::hexlike() const -{ - if (!sLog.HasLogLevelOrHigher(LOG_LVL_DEBUG)) // optimize disabled debug output - return; - - std::ostringstream ss; - ss << "STORAGE_SIZE: " << size() << "\n"; - - if (sLog.IsIncludeTime()) - ss << " "; - - size_t j = 1, k = 1; - - for (size_t i = 0; i < size(); ++i) - { - if ((i == (j * 8)) && ((i != (k * 16)))) - { - ss << "| "; - ++j; - } - else if (i == (k * 16)) - { - ss << "\n"; - - if (sLog.IsIncludeTime()) - ss << " "; - - ++k; - ++j; - } - - char buf[4]; - snprintf(buf, 4, "%02X", read(i)); - ss << buf << " "; - } - - sLog.outDebug(ss.str().c_str()); -} diff --git a/src/shared/ByteBuffer.h b/src/shared/ByteBuffer.h index d6cd6b473..21581f086 100644 --- a/src/shared/ByteBuffer.h +++ b/src/shared/ByteBuffer.h @@ -135,7 +135,10 @@ class ByteBuffer } // constructor - ByteBuffer(size_t res, bool init = false); + ByteBuffer(size_t res): _rpos(0), _wpos(0), _bitpos(8), _curbitval(0) + { + _storage.reserve(res); + } // copy constructor ByteBuffer(const ByteBuffer &buf) : _rpos(buf._rpos), _wpos(buf._wpos), diff --git a/src/shared/revision_nr.h b/src/shared/revision_nr.h index ede3aa37b..f85a59063 100644 --- a/src/shared/revision_nr.h +++ b/src/shared/revision_nr.h @@ -1,4 +1,4 @@ #ifndef __REVISION_NR_H__ #define __REVISION_NR_H__ -#define REVISION_NR "0183" +#define REVISION_NR "0184" #endif // __REVISION_NR_H__