TrinityCore
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Modules Pages
ByteBuffer Class Reference

#include <ByteBuffer.h>

Public Member Functions

 ByteBuffer ()
 
 ByteBuffer (size_t reserve)
 
 ByteBuffer (ByteBuffer &&buf)
 
 ByteBuffer (ByteBuffer const &right)
 
 ByteBuffer (MessageBuffer &&buffer)
 
std::vector< uint8 > && Move ()
 
ByteBufferoperator= (ByteBuffer const &right)
 
ByteBufferoperator= (ByteBuffer &&right)
 
virtual ~ByteBuffer ()
 
void clear ()
 
template<typename T >
void append (T value)
 
void FlushBits ()
 
void ResetBitPos ()
 
bool WriteBit (uint32 bit)
 
bool ReadBit ()
 
template<typename T >
void WriteBits (T value, int32 bits)
 
uint32 ReadBits (int32 bits)
 
void ReadByteSeq (uint8 &b)
 
void WriteByteSeq (uint8 b)
 
template<typename T >
void put (size_t pos, T value)
 
template<>
void read_skip ()
 
template<>
void read_skip ()
 

Static Public Attributes

static size_t const DEFAULT_SIZE = 0x1000
 
static uint8 const InitialBitPos = 8
 

PutBits

Places specified amount of bits of value at specified position in packet. To ensure all bits are correctly written, only call this method after bit flush has been performed

Parameters
posPosition to place the value at, in bits. The entire value must fit in the packet It is advised to obtain the position using bitwpos() function.
valueData to write.
bitCountNumber of bits to store the value on.
size_t _rpos
 
size_t _wpos
 
size_t _bitpos
 
uint8 _curbitval
 
std::vector< uint8_storage
 
template<typename T >
void PutBits (size_t pos, T value, uint32 bitCount)
 
ByteBufferoperator<< (uint8 value)
 
ByteBufferoperator<< (uint16 value)
 
ByteBufferoperator<< (uint32 value)
 
ByteBufferoperator<< (uint64 value)
 
ByteBufferoperator<< (int8 value)
 
ByteBufferoperator<< (int16 value)
 
ByteBufferoperator<< (int32 value)
 
ByteBufferoperator<< (int64 value)
 
ByteBufferoperator<< (float value)
 
ByteBufferoperator<< (double value)
 
ByteBufferoperator<< (const std::string &value)
 
ByteBufferoperator<< (const char *str)
 
ByteBufferoperator>> (bool &value)
 
ByteBufferoperator>> (uint8 &value)
 
ByteBufferoperator>> (uint16 &value)
 
ByteBufferoperator>> (uint32 &value)
 
ByteBufferoperator>> (uint64 &value)
 
ByteBufferoperator>> (int8 &value)
 
ByteBufferoperator>> (int16 &value)
 
ByteBufferoperator>> (int32 &value)
 
ByteBufferoperator>> (int64 &value)
 
ByteBufferoperator>> (float &value)
 
ByteBufferoperator>> (double &value)
 
ByteBufferoperator>> (std::string &value)
 
uint8operator[] (size_t const pos)
 
uint8 constoperator[] (size_t const pos) const
 
size_t rpos () const
 
size_t rpos (size_t rpos_)
 
void rfinish ()
 
size_t wpos () const
 
size_t wpos (size_t wpos_)
 
size_t bitwpos () const
 Returns position of last written bit. More...
 
size_t bitwpos (size_t newPos)
 
template<typename T >
void read_skip ()
 
void read_skip (size_t skip)
 
template<typename T >
read ()
 
template<typename T >
read (size_t pos) const
 
void read (uint8 *dest, size_t len)
 
void ReadPackedUInt64 (uint64 &guid)
 
void ReadPackedUInt64 (uint8 mask, uint64 &value)
 
std::string ReadString (uint32 length)
 
void WriteString (std::string const &str)
 
void WriteString (char const *str, size_t len)
 
uint32 ReadPackedTime ()
 
ByteBufferReadPackedTime (uint32 &time)
 
uint8contents ()
 
uint8 constcontents () const
 
size_t size () const
 
bool empty () const
 
void resize (size_t newsize)
 
void reserve (size_t ressize)
 
void append (const char *src, size_t cnt)
 
template<class T >
void append (const T *src, size_t cnt)
 
void append (const uint8 *src, size_t cnt)
 
void append (const ByteBuffer &buffer)
 
void appendPackXYZ (float x, float y, float z)
 
void AppendPackedUInt64 (uint64 guid)
 
void AppendPackedTime (time_t time)
 
void put (size_t pos, const uint8 *src, size_t cnt)
 
void print_storage () const
 
void textlike () const
 
void hexlike () const
 
static size_t PackUInt64 (uint64 value, uint8 *mask, uint8 *result)
 

Constructor & Destructor Documentation

ByteBuffer::ByteBuffer ( )
inline
78  {
79  _storage.reserve(DEFAULT_SIZE);
80  }
uint8 _curbitval
Definition: ByteBuffer.h:706
std::vector< uint8 > _storage
Definition: ByteBuffer.h:707
static uint8 const InitialBitPos
Definition: ByteBuffer.h:74
size_t _bitpos
Definition: ByteBuffer.h:705
static size_t const DEFAULT_SIZE
Definition: ByteBuffer.h:73
size_t _wpos
Definition: ByteBuffer.h:705
size_t _rpos
Definition: ByteBuffer.h:705
ByteBuffer::ByteBuffer ( size_t  reserve)
inline
83  {
84  _storage.reserve(reserve);
85  }
uint8 _curbitval
Definition: ByteBuffer.h:706
std::vector< uint8 > _storage
Definition: ByteBuffer.h:707
void reserve(size_t ressize)
Definition: ByteBuffer.h:597
static uint8 const InitialBitPos
Definition: ByteBuffer.h:74
size_t _bitpos
Definition: ByteBuffer.h:705
size_t _wpos
Definition: ByteBuffer.h:705
size_t _rpos
Definition: ByteBuffer.h:705
ByteBuffer::ByteBuffer ( ByteBuffer &&  buf)
inline
87  : _rpos(buf._rpos), _wpos(buf._wpos),
88  _bitpos(buf._bitpos), _curbitval(buf._curbitval), _storage(buf.Move()) { }
uint8 _curbitval
Definition: ByteBuffer.h:706
std::vector< uint8 > _storage
Definition: ByteBuffer.h:707
std::vector< uint8 > && Move()
Definition: ByteBuffer.h:95
size_t _bitpos
Definition: ByteBuffer.h:705
size_t _wpos
Definition: ByteBuffer.h:705
size_t _rpos
Definition: ByteBuffer.h:705
ByteBuffer::ByteBuffer ( ByteBuffer const right)
inline
90  : _rpos(right._rpos), _wpos(right._wpos),
91  _bitpos(right._bitpos), _curbitval(right._curbitval), _storage(right._storage) { }
uint8 _curbitval
Definition: ByteBuffer.h:706
std::vector< uint8 > _storage
Definition: ByteBuffer.h:707
size_t _bitpos
Definition: ByteBuffer.h:705
size_t _wpos
Definition: ByteBuffer.h:705
size_t _rpos
Definition: ByteBuffer.h:705
ByteBuffer::ByteBuffer ( MessageBuffer &&  buffer)
25  : _rpos(0), _wpos(0), _bitpos(InitialBitPos), _curbitval(0), _storage(buffer.Move())
26 {
27 }
std::vector< uint8 > && Move()
Definition: MessageBuffer.h:101
uint8 _curbitval
Definition: ByteBuffer.h:706
std::vector< uint8 > _storage
Definition: ByteBuffer.h:707
static uint8 const InitialBitPos
Definition: ByteBuffer.h:74
size_t _bitpos
Definition: ByteBuffer.h:705
size_t _wpos
Definition: ByteBuffer.h:705
size_t _rpos
Definition: ByteBuffer.h:705
virtual ByteBuffer::~ByteBuffer ( )
inlinevirtual
132 { }

Member Function Documentation

template<typename T >
void ByteBuffer::append ( value)
inline
144  {
145  static_assert(std::is_fundamental<T>::value, "append(compound)");
147  append((uint8 *)&value, sizeof(value));
148  }
void EndianConvert(T &val)
Definition: ByteConverter.h:48
void append(T value)
Definition: ByteBuffer.h:143
uint8_t uint8
Definition: Define.h:152
const FieldDescriptor value
Definition: descriptor.h:1522

+ Here is the call graph for this function:

+ Here is the caller graph for this function:

void ByteBuffer::append ( const char *  src,
size_t  cnt 
)
inline
604  {
605  return append((const uint8 *)src, cnt);
606  }
void append(T value)
Definition: ByteBuffer.h:143
uint8_t uint8
Definition: Define.h:152

+ Here is the call graph for this function:

template<class T >
void ByteBuffer::append ( const T *  src,
size_t  cnt 
)
inline
609  {
610  return append((const uint8 *)src, cnt * sizeof(T));
611  }
void append(T value)
Definition: ByteBuffer.h:143
uint8_t uint8
Definition: Define.h:152

+ Here is the call graph for this function:

void ByteBuffer::append ( const uint8 src,
size_t  cnt 
)
inline
614  {
615  if (!cnt)
616  throw ByteBufferSourceException(_wpos, size(), cnt);
617 
618  if (!src)
619  throw ByteBufferSourceException(_wpos, size(), cnt);
620 
621  ASSERT(size() < 10000000);
622 
623  FlushBits();
624 
625  if (_storage.size() < _wpos + cnt)
626  _storage.resize(_wpos + cnt);
627  std::memcpy(&_storage[_wpos], src, cnt);
628  _wpos += cnt;
629  }
Definition: ByteBuffer.h:62
void FlushBits()
Definition: ByteBuffer.h:150
std::vector< uint8 > _storage
Definition: ByteBuffer.h:707
size_t size() const
Definition: ByteBuffer.h:587
#define ASSERT
Definition: Errors.h:55
size_t _wpos
Definition: ByteBuffer.h:705
void ByteBuffer::append ( const ByteBuffer buffer)
inline
632  {
633  if (buffer.wpos())
634  append(buffer.contents(), buffer.wpos());
635  }
uint8 * contents()
Definition: ByteBuffer.h:573
size_t wpos() const
Definition: ByteBuffer.h:454
void append(T value)
Definition: ByteBuffer.h:143

+ Here is the call graph for this function:

void ByteBuffer::AppendPackedTime ( time_t  time)
inline
681  {
682  tm lt;
683  localtime_r(&time, &lt);
684  append<uint32>((lt.tm_year - 100) << 24 | lt.tm_mon << 20 | (lt.tm_mday - 1) << 14 | lt.tm_wday << 11 | lt.tm_hour << 6 | lt.tm_min);
685  }
TC_COMMON_API struct tm * localtime_r(const time_t *time, struct tm *result)

+ Here is the call graph for this function:

+ Here is the caller graph for this function:

void ByteBuffer::AppendPackedUInt64 ( uint64  guid)
inline
648  {
649  uint8 mask = 0;
650  size_t pos = wpos();
651  *this << uint8(mask);
652 
653  uint8 packed[8];
654  if (size_t packedSize = PackUInt64(guid, &mask, packed))
655  append(packed, packedSize);
656 
657  put<uint8>(pos, mask);
658  }
size_t wpos() const
Definition: ByteBuffer.h:454
static size_t PackUInt64(uint64 value, uint8 *mask, uint8 *result)
Definition: ByteBuffer.h:660
void append(T value)
Definition: ByteBuffer.h:143
uint8_t uint8
Definition: g3dmath.h:164
uint8_t uint8
Definition: Define.h:152

+ Here is the call graph for this function:

void ByteBuffer::appendPackXYZ ( float  x,
float  y,
float  z 
)
inline
639  {
640  uint32 packed = 0;
641  packed |= ((int)(x / 0.25f) & 0x7FF);
642  packed |= ((int)(y / 0.25f) & 0x7FF) << 11;
643  packed |= ((int)(z / 0.25f) & 0x3FF) << 22;
644  *this << packed;
645  }
G3D::int16 z
Definition: Vector3int16.h:46
uint32_t uint32
Definition: Define.h:150
G3D::int16 y
Definition: Vector2int16.h:38
G3D::int16 x
Definition: Vector2int16.h:37

+ Here is the caller graph for this function:

size_t ByteBuffer::bitwpos ( ) const
inline

Returns position of last written bit.

463 { return _wpos * 8 + 8 - _bitpos; }
size_t _bitpos
Definition: ByteBuffer.h:705
size_t _wpos
Definition: ByteBuffer.h:705
size_t ByteBuffer::bitwpos ( size_t  newPos)
inline
466  {
467  _wpos = newPos / 8;
468  _bitpos = 8 - (newPos % 8);
469  return _wpos * 8 + 8 - _bitpos;
470  }
size_t _bitpos
Definition: ByteBuffer.h:705
size_t _wpos
Definition: ByteBuffer.h:705
void ByteBuffer::clear ( )
inline
135  {
136  _rpos = 0;
137  _wpos = 0;
139  _curbitval = 0;
140  _storage.clear();
141  }
uint8 _curbitval
Definition: ByteBuffer.h:706
std::vector< uint8 > _storage
Definition: ByteBuffer.h:707
static uint8 const InitialBitPos
Definition: ByteBuffer.h:74
size_t _bitpos
Definition: ByteBuffer.h:705
size_t _wpos
Definition: ByteBuffer.h:705
size_t _rpos
Definition: ByteBuffer.h:705

+ Here is the caller graph for this function:

uint8* ByteBuffer::contents ( )
inline
574  {
575  if (_storage.empty())
576  throw ByteBufferException();
577  return _storage.data();
578  }
std::vector< uint8 > _storage
Definition: ByteBuffer.h:707
Definition: ByteBuffer.h:40

+ Here is the caller graph for this function:

uint8 const* ByteBuffer::contents ( ) const
inline
581  {
582  if (_storage.empty())
583  throw ByteBufferException();
584  return _storage.data();
585  }
std::vector< uint8 > _storage
Definition: ByteBuffer.h:707
Definition: ByteBuffer.h:40
bool ByteBuffer::empty ( ) const
inline
588 { return _storage.empty(); }
std::vector< uint8 > _storage
Definition: ByteBuffer.h:707

+ Here is the caller graph for this function:

void ByteBuffer::FlushBits ( )
inline
151  {
152  if (_bitpos == 8)
153  return;
154 
155  _bitpos = 8;
156 
157  append((uint8 *)&_curbitval, sizeof(uint8));
158  _curbitval = 0;
159  }
uint8 _curbitval
Definition: ByteBuffer.h:706
void append(T value)
Definition: ByteBuffer.h:143
size_t _bitpos
Definition: ByteBuffer.h:705
uint8_t uint8
Definition: Define.h:152

+ Here is the call graph for this function:

+ Here is the caller graph for this function:

void ByteBuffer::hexlike ( ) const
83 {
84  if (!sLog->ShouldLog("network", LOG_LEVEL_TRACE)) // optimize disabled trace output
85  return;
86 
87  uint32 j = 1, k = 1;
88 
89  std::ostringstream o;
90  o << "STORAGE_SIZE: " << size();
91 
92  for (uint32 i = 0; i < size(); ++i)
93  {
94  char buf[3];
95  snprintf(buf, 3, "%2X ", read<uint8>(i));
96  if ((i == (j * 8)) && ((i != (k * 16))))
97  {
98  o << "| ";
99  ++j;
100  }
101  else if (i == (k * 16))
102  {
103  o << "\n";
104  ++k;
105  ++j;
106  }
107 
108  o << buf;
109  }
110  o << " ";
111  TC_LOG_TRACE("network", "%s", o.str().c_str());
112 }
Definition: Appender.h:34
#define snprintf
Definition: Common.h:76
#define sLog
Definition: Log.h:154
size_t size() const
Definition: ByteBuffer.h:587
#define TC_LOG_TRACE(filterType__,...)
Definition: Log.h:195
uint32_t uint32
Definition: Define.h:150

+ Here is the call graph for this function:

+ Here is the caller graph for this function:

std::vector<uint8>&& ByteBuffer::Move ( )
inline
96  {
97  _rpos = 0;
98  _wpos = 0;
100  _curbitval = 0;
101  return std::move(_storage);
102  }
uint8 _curbitval
Definition: ByteBuffer.h:706
std::vector< uint8 > _storage
Definition: ByteBuffer.h:707
static uint8 const InitialBitPos
Definition: ByteBuffer.h:74
size_t _bitpos
Definition: ByteBuffer.h:705
size_t _wpos
Definition: ByteBuffer.h:705
size_t _rpos
Definition: ByteBuffer.h:705
ByteBuffer& ByteBuffer::operator<< ( uint8  value)
inline
266  {
267  append<uint8>(value);
268  return *this;
269  }
const FieldDescriptor value
Definition: descriptor.h:1522
ByteBuffer& ByteBuffer::operator<< ( uint16  value)
inline
272  {
273  append<uint16>(value);
274  return *this;
275  }
const FieldDescriptor value
Definition: descriptor.h:1522
ByteBuffer& ByteBuffer::operator<< ( uint32  value)
inline
278  {
279  append<uint32>(value);
280  return *this;
281  }
const FieldDescriptor value
Definition: descriptor.h:1522
ByteBuffer& ByteBuffer::operator<< ( uint64  value)
inline
284  {
285  append<uint64>(value);
286  return *this;
287  }
const FieldDescriptor value
Definition: descriptor.h:1522
ByteBuffer& ByteBuffer::operator<< ( int8  value)
inline
291  {
292  append<int8>(value);
293  return *this;
294  }
const FieldDescriptor value
Definition: descriptor.h:1522
ByteBuffer& ByteBuffer::operator<< ( int16  value)
inline
297  {
298  append<int16>(value);
299  return *this;
300  }
const FieldDescriptor value
Definition: descriptor.h:1522
ByteBuffer& ByteBuffer::operator<< ( int32  value)
inline
303  {
304  append<int32>(value);
305  return *this;
306  }
const FieldDescriptor value
Definition: descriptor.h:1522
ByteBuffer& ByteBuffer::operator<< ( int64  value)
inline
309  {
310  append<int64>(value);
311  return *this;
312  }
const FieldDescriptor value
Definition: descriptor.h:1522
ByteBuffer& ByteBuffer::operator<< ( float  value)
inline
316  {
317  append<float>(value);
318  return *this;
319  }
const FieldDescriptor value
Definition: descriptor.h:1522
ByteBuffer& ByteBuffer::operator<< ( double  value)
inline
322  {
323  append<double>(value);
324  return *this;
325  }
const FieldDescriptor value
Definition: descriptor.h:1522
ByteBuffer& ByteBuffer::operator<< ( const std::string &  value)
inline
328  {
329  if (size_t len = value.length())
330  append((uint8 const*)value.c_str(), len);
331  append<uint8>(0);
332  return *this;
333  }
void append(T value)
Definition: ByteBuffer.h:143
uint8_t uint8
Definition: Define.h:152
const FieldDescriptor value
Definition: descriptor.h:1522

+ Here is the call graph for this function:

ByteBuffer& ByteBuffer::operator<< ( const char *  str)
inline
336  {
337  if (size_t len = (str ? strlen(str) : 0))
338  append((uint8 const*)str, len);
339  append<uint8>(0);
340  return *this;
341  }
void append(T value)
Definition: ByteBuffer.h:143
uint8_t uint8
Definition: Define.h:152

+ Here is the call graph for this function:

ByteBuffer& ByteBuffer::operator= ( ByteBuffer const right)
inline
105  {
106  if (this != &right)
107  {
108  _rpos = right._rpos;
109  _wpos = right._wpos;
110  _bitpos = right._bitpos;
111  _curbitval = right._curbitval;
112  _storage = right._storage;
113  }
114 
115  return *this;
116  }
uint8 _curbitval
Definition: ByteBuffer.h:706
std::vector< uint8 > _storage
Definition: ByteBuffer.h:707
size_t _bitpos
Definition: ByteBuffer.h:705
size_t _wpos
Definition: ByteBuffer.h:705
size_t _rpos
Definition: ByteBuffer.h:705

+ Here is the caller graph for this function:

ByteBuffer& ByteBuffer::operator= ( ByteBuffer &&  right)
inline
119  {
120  if (this != &right)
121  {
122  _rpos = right._rpos;
123  _wpos = right._wpos;
124  _bitpos = right._bitpos;
125  _curbitval = right._curbitval;
126  _storage = right.Move();
127  }
128 
129  return *this;
130  }
uint8 _curbitval
Definition: ByteBuffer.h:706
std::vector< uint8 > _storage
Definition: ByteBuffer.h:707
std::vector< uint8 > && Move()
Definition: ByteBuffer.h:95
size_t _bitpos
Definition: ByteBuffer.h:705
size_t _wpos
Definition: ByteBuffer.h:705
size_t _rpos
Definition: ByteBuffer.h:705
ByteBuffer& ByteBuffer::operator>> ( bool value)
inline
344  {
345  value = read<char>() > 0 ? true : false;
346  return *this;
347  }
const FieldDescriptor value
Definition: descriptor.h:1522
ByteBuffer& ByteBuffer::operator>> ( uint8 value)
inline
350  {
351  value = read<uint8>();
352  return *this;
353  }
const FieldDescriptor value
Definition: descriptor.h:1522
ByteBuffer& ByteBuffer::operator>> ( uint16 value)
inline
356  {
357  value = read<uint16>();
358  return *this;
359  }
const FieldDescriptor value
Definition: descriptor.h:1522
ByteBuffer& ByteBuffer::operator>> ( uint32 value)
inline
362  {
363  value = read<uint32>();
364  return *this;
365  }
const FieldDescriptor value
Definition: descriptor.h:1522
ByteBuffer& ByteBuffer::operator>> ( uint64 value)
inline
368  {
369  value = read<uint64>();
370  return *this;
371  }
const FieldDescriptor value
Definition: descriptor.h:1522
ByteBuffer& ByteBuffer::operator>> ( int8 value)
inline
375  {
376  value = read<int8>();
377  return *this;
378  }
const FieldDescriptor value
Definition: descriptor.h:1522
ByteBuffer& ByteBuffer::operator>> ( int16 value)
inline
381  {
382  value = read<int16>();
383  return *this;
384  }
const FieldDescriptor value
Definition: descriptor.h:1522
ByteBuffer& ByteBuffer::operator>> ( int32 value)
inline
387  {
388  value = read<int32>();
389  return *this;
390  }
const FieldDescriptor value
Definition: descriptor.h:1522
ByteBuffer& ByteBuffer::operator>> ( int64 value)
inline
393  {
394  value = read<int64>();
395  return *this;
396  }
const FieldDescriptor value
Definition: descriptor.h:1522
ByteBuffer& ByteBuffer::operator>> ( float &  value)
inline
399  {
400  value = read<float>();
401  if (!std::isfinite(value))
402  throw ByteBufferException();
403  return *this;
404  }
Definition: ByteBuffer.h:40
const FieldDescriptor value
Definition: descriptor.h:1522
ByteBuffer& ByteBuffer::operator>> ( double &  value)
inline
407  {
408  value = read<double>();
409  if (!std::isfinite(value))
410  throw ByteBufferException();
411  return *this;
412  }
Definition: ByteBuffer.h:40
const FieldDescriptor value
Definition: descriptor.h:1522
ByteBuffer& ByteBuffer::operator>> ( std::string &  value)
inline
415  {
416  value.clear();
417  while (rpos() < size()) // prevent crash at wrong string format in packet
418  {
419  char c = read<char>();
420  if (c == 0)
421  break;
422  value += c;
423  }
424  return *this;
425  }
size_t size() const
Definition: ByteBuffer.h:587
const FieldDescriptor value
Definition: descriptor.h:1522
size_t rpos() const
Definition: ByteBuffer.h:441

+ Here is the call graph for this function:

uint8& ByteBuffer::operator[] ( size_t const  pos)
inline
428  {
429  if (pos >= size())
430  throw ByteBufferPositionException(false, pos, 1, size());
431  return _storage[pos];
432  }
std::vector< uint8 > _storage
Definition: ByteBuffer.h:707
Definition: ByteBuffer.h:54
size_t size() const
Definition: ByteBuffer.h:587
uint8 const& ByteBuffer::operator[] ( size_t const  pos) const
inline
435  {
436  if (pos >= size())
437  throw ByteBufferPositionException(false, pos, 1, size());
438  return _storage[pos];
439  }
std::vector< uint8 > _storage
Definition: ByteBuffer.h:707
Definition: ByteBuffer.h:54
size_t size() const
Definition: ByteBuffer.h:587
static size_t ByteBuffer::PackUInt64 ( uint64  value,
uint8 mask,
uint8 result 
)
inlinestatic
661  {
662  size_t resultSize = 0;
663  *mask = 0;
664  memset(result, 0, 8);
665 
666  for (uint8 i = 0; value != 0; ++i)
667  {
668  if (value & 0xFF)
669  {
670  *mask |= uint8(1 << i);
671  result[resultSize++] = uint8(value & 0xFF);
672  }
673 
674  value >>= 8;
675  }
676 
677  return resultSize;
678  }
uint8_t uint8
Definition: g3dmath.h:164
uint8_t uint8
Definition: Define.h:152
const FieldDescriptor value
Definition: descriptor.h:1522

+ Here is the caller graph for this function:

void ByteBuffer::print_storage ( ) const
52 {
53  if (!sLog->ShouldLog("network", LOG_LEVEL_TRACE)) // optimize disabled trace output
54  return;
55 
56  std::ostringstream o;
57  o << "STORAGE_SIZE: " << size();
58  for (uint32 i = 0; i < size(); ++i)
59  o << read<uint8>(i) << " - ";
60  o << " ";
61 
62  TC_LOG_TRACE("network", "%s", o.str().c_str());
63 }
Definition: Appender.h:34
#define sLog
Definition: Log.h:154
size_t size() const
Definition: ByteBuffer.h:587
#define TC_LOG_TRACE(filterType__,...)
Definition: Log.h:195
uint32_t uint32
Definition: Define.h:150

+ Here is the call graph for this function:

+ Here is the caller graph for this function:

template<typename T >
void ByteBuffer::put ( size_t  pos,
value 
)
inline
228  {
229  static_assert(std::is_fundamental<T>::value, "append(compound)");
231  put(pos, (uint8 *)&value, sizeof(value));
232  }
void EndianConvert(T &val)
Definition: ByteConverter.h:48
void put(size_t pos, T value)
Definition: ByteBuffer.h:227
uint8_t uint8
Definition: Define.h:152
const FieldDescriptor value
Definition: descriptor.h:1522

+ Here is the call graph for this function:

+ Here is the caller graph for this function:

void ByteBuffer::put ( size_t  pos,
const uint8 src,
size_t  cnt 
)
inline
688  {
689  if (pos + cnt > size())
690  throw ByteBufferPositionException(true, pos, cnt, size());
691 
692  if (!src)
693  throw ByteBufferSourceException(_wpos, size(), cnt);
694 
695  std::memcpy(&_storage[pos], src, cnt);
696  }
Definition: ByteBuffer.h:62
std::vector< uint8 > _storage
Definition: ByteBuffer.h:707
Definition: ByteBuffer.h:54
size_t size() const
Definition: ByteBuffer.h:587
size_t _wpos
Definition: ByteBuffer.h:705
template<typename T >
void ByteBuffer::PutBits ( size_t  pos,
value,
uint32  bitCount 
)
inline
247  {
248  if (!bitCount)
249  throw ByteBufferSourceException((pos + bitCount) / 8, size(), 0);
250 
251  if (pos + bitCount > size() * 8)
252  throw ByteBufferPositionException(false, (pos + bitCount) / 8, size(), (bitCount - 1) / 8 + 1);
253 
254  for (uint32 i = 0; i < bitCount; ++i)
255  {
256  size_t wp = (pos + i) / 8;
257  size_t bit = (pos + i) % 8;
258  if ((value >> (bitCount - i - 1)) & 1)
259  _storage[wp] |= 1 << (7 - bit);
260  else
261  _storage[wp] &= ~(1 << (7 - bit));
262  }
263  }
Definition: ByteBuffer.h:62
std::vector< uint8 > _storage
Definition: ByteBuffer.h:707
Definition: ByteBuffer.h:54
size_t size() const
Definition: ByteBuffer.h:587
uint32_t uint32
Definition: Define.h:150
const FieldDescriptor value
Definition: descriptor.h:1522
template<typename T >
T ByteBuffer::read ( )
inline
485  {
486  ResetBitPos();
487  T r = read<T>(_rpos);
488  _rpos += sizeof(T);
489  return r;
490  }
void ResetBitPos()
Definition: ByteBuffer.h:161
size_t _rpos
Definition: ByteBuffer.h:705

+ Here is the caller graph for this function:

template<typename T >
T ByteBuffer::read ( size_t  pos) const
inline
493  {
494  if (pos + sizeof(T) > size())
495  throw ByteBufferPositionException(false, pos, sizeof(T), size());
496  T val = *((T const*)&_storage[pos]);
497  EndianConvert(val);
498  return val;
499  }
void EndianConvert(T &val)
Definition: ByteConverter.h:48
std::vector< uint8 > _storage
Definition: ByteBuffer.h:707
Definition: ByteBuffer.h:54
size_t size() const
Definition: ByteBuffer.h:587

+ Here is the call graph for this function:

void ByteBuffer::read ( uint8 dest,
size_t  len 
)
inline
502  {
503  if (_rpos + len > size())
504  throw ByteBufferPositionException(false, _rpos, len, size());
505 
506  ResetBitPos();
507  std::memcpy(dest, &_storage[_rpos], len);
508  _rpos += len;
509  }
void ResetBitPos()
Definition: ByteBuffer.h:161
std::vector< uint8 > _storage
Definition: ByteBuffer.h:707
Definition: ByteBuffer.h:54
size_t size() const
Definition: ByteBuffer.h:587
size_t _rpos
Definition: ByteBuffer.h:705
template<typename T >
void ByteBuffer::read_skip ( )
inline
473 { read_skip(sizeof(T)); }
void read_skip()
Definition: ByteBuffer.h:473

+ Here is the call graph for this function:

+ Here is the caller graph for this function:

void ByteBuffer::read_skip ( size_t  skip)
inline
476  {
477  if (_rpos + skip > size())
478  throw ByteBufferPositionException(false, _rpos, skip, size());
479 
480  ResetBitPos();
481  _rpos += skip;
482  }
void ResetBitPos()
Definition: ByteBuffer.h:161
Definition: ByteBuffer.h:54
size_t size() const
Definition: ByteBuffer.h:587
size_t _rpos
Definition: ByteBuffer.h:705
template<>
void ByteBuffer::read_skip ( )
inline
799 {
800  std::string temp;
801  *this >> temp;
802 }
template<>
void ByteBuffer::read_skip ( )
inline
806 {
807  read_skip<char*>();
808 }
bool ByteBuffer::ReadBit ( )
inline
187  {
188  ++_bitpos;
189  if (_bitpos > 7)
190  {
191  _curbitval = read<uint8>();
192  _bitpos = 0;
193  }
194 
195  return ((_curbitval >> (7-_bitpos)) & 1) != 0;
196  }
uint8 _curbitval
Definition: ByteBuffer.h:706
size_t _bitpos
Definition: ByteBuffer.h:705

+ Here is the caller graph for this function:

uint32 ByteBuffer::ReadBits ( int32  bits)
inline
205  {
206  uint32 value = 0;
207  for (int32 i = bits - 1; i >= 0; --i)
208  if (ReadBit())
209  value |= (1 << (i));
210 
211  return value;
212  }
int32_t int32
Definition: Define.h:146
uint32_t uint32
Definition: Define.h:150
uint16 bits() const
Returns the underlying bits in this representation. Equivalent to:
Definition: unorm16.h:89
const FieldDescriptor value
Definition: descriptor.h:1522
bool ReadBit()
Definition: ByteBuffer.h:186

+ Here is the caller graph for this function:

void ByteBuffer::ReadByteSeq ( uint8 b)
inline
216  {
217  if (b != 0)
218  b ^= read<uint8>();
219  }

+ Here is the caller graph for this function:

uint32 ByteBuffer::ReadPackedTime ( )
inline
553  {
554  uint32 packedDate = read<uint32>();
555  tm lt = tm();
556 
557  lt.tm_min = packedDate & 0x3F;
558  lt.tm_hour = (packedDate >> 6) & 0x1F;
559  //lt.tm_wday = (packedDate >> 11) & 7;
560  lt.tm_mday = ((packedDate >> 14) & 0x3F) + 1;
561  lt.tm_mon = (packedDate >> 20) & 0xF;
562  lt.tm_year = ((packedDate >> 24) & 0x1F) + 100;
563 
564  return uint32(mktime(&lt));
565  }
uint32_t uint32
Definition: Define.h:150
uint32_t uint32
Definition: g3dmath.h:168

+ Here is the caller graph for this function:

ByteBuffer& ByteBuffer::ReadPackedTime ( uint32 time)
inline
568  {
569  time = ReadPackedTime();
570  return *this;
571  }
uint32 ReadPackedTime()
Definition: ByteBuffer.h:552
void ByteBuffer::ReadPackedUInt64 ( uint64 guid)
inline
512  {
513  guid = 0;
514  ReadPackedUInt64(read<uint8>(), guid);
515  }
void ReadPackedUInt64(uint64 &guid)
Definition: ByteBuffer.h:511

+ Here is the caller graph for this function:

void ByteBuffer::ReadPackedUInt64 ( uint8  mask,
uint64 value 
)
inline
518  {
519  for (uint32 i = 0; i < 8; ++i)
520  if (mask & (uint8(1) << i))
521  value |= (uint64(read<uint8>()) << (i * 8));
522  }
uint64_t uint64
Definition: g3dmath.h:170
uint32_t uint32
Definition: Define.h:150
uint8_t uint8
Definition: g3dmath.h:164
const FieldDescriptor value
Definition: descriptor.h:1522
std::string ByteBuffer::ReadString ( uint32  length)
inline
525  {
526  if (_rpos + length > size())
527  throw ByteBufferPositionException(false, _rpos, length, size());
528 
529  ResetBitPos();
530  if (!length)
531  return std::string();
532 
533  std::string str((char const*)&_storage[_rpos], length);
534  _rpos += length;
535  return str;
536  }
void ResetBitPos()
Definition: ByteBuffer.h:161
std::vector< uint8 > _storage
Definition: ByteBuffer.h:707
Definition: ByteBuffer.h:54
size_t size() const
Definition: ByteBuffer.h:587
float length(float v)
Definition: vectorMath.h:208
size_t _rpos
Definition: ByteBuffer.h:705

+ Here is the call graph for this function:

+ Here is the caller graph for this function:

void ByteBuffer::reserve ( size_t  ressize)
inline
598  {
599  if (ressize > size())
600  _storage.reserve(ressize);
601  }
std::vector< uint8 > _storage
Definition: ByteBuffer.h:707
size_t size() const
Definition: ByteBuffer.h:587

+ Here is the caller graph for this function:

void ByteBuffer::ResetBitPos ( )
inline
162  {
163  if (_bitpos > 7)
164  return;
165 
166  _bitpos = 8;
167  _curbitval = 0;
168  }
uint8 _curbitval
Definition: ByteBuffer.h:706
size_t _bitpos
Definition: ByteBuffer.h:705

+ Here is the caller graph for this function:

void ByteBuffer::resize ( size_t  newsize)
inline
591  {
592  _storage.resize(newsize, 0);
593  _rpos = 0;
594  _wpos = size();
595  }
std::vector< uint8 > _storage
Definition: ByteBuffer.h:707
size_t size() const
Definition: ByteBuffer.h:587
size_t _wpos
Definition: ByteBuffer.h:705
size_t _rpos
Definition: ByteBuffer.h:705

+ Here is the caller graph for this function:

void ByteBuffer::rfinish ( )
inline
450  {
451  _rpos = wpos();
452  }
size_t wpos() const
Definition: ByteBuffer.h:454
size_t _rpos
Definition: ByteBuffer.h:705

+ Here is the caller graph for this function:

size_t ByteBuffer::rpos ( ) const
inline
441 { return _rpos; }
size_t _rpos
Definition: ByteBuffer.h:705

+ Here is the caller graph for this function:

size_t ByteBuffer::rpos ( size_t  rpos_)
inline
444  {
445  _rpos = rpos_;
446  return _rpos;
447  }
size_t _rpos
Definition: ByteBuffer.h:705
size_t ByteBuffer::size ( ) const
inline
587 { return _storage.size(); }
std::vector< uint8 > _storage
Definition: ByteBuffer.h:707

+ Here is the caller graph for this function:

void ByteBuffer::textlike ( ) const
66 {
67  if (!sLog->ShouldLog("network", LOG_LEVEL_TRACE)) // optimize disabled trace output
68  return;
69 
70  std::ostringstream o;
71  o << "STORAGE_SIZE: " << size();
72  for (uint32 i = 0; i < size(); ++i)
73  {
74  char buf[2];
75  snprintf(buf, 2, "%c", read<uint8>(i));
76  o << buf;
77  }
78  o << " ";
79  TC_LOG_TRACE("network", "%s", o.str().c_str());
80 }
Definition: Appender.h:34
#define snprintf
Definition: Common.h:76
#define sLog
Definition: Log.h:154
size_t size() const
Definition: ByteBuffer.h:587
#define TC_LOG_TRACE(filterType__,...)
Definition: Log.h:195
uint32_t uint32
Definition: Define.h:150

+ Here is the call graph for this function:

size_t ByteBuffer::wpos ( ) const
inline
454 { return _wpos; }
size_t _wpos
Definition: ByteBuffer.h:705

+ Here is the caller graph for this function:

size_t ByteBuffer::wpos ( size_t  wpos_)
inline
457  {
458  _wpos = wpos_;
459  return _wpos;
460  }
size_t _wpos
Definition: ByteBuffer.h:705
bool ByteBuffer::WriteBit ( uint32  bit)
inline
171  {
172  --_bitpos;
173  if (bit)
174  _curbitval |= (1 << (_bitpos));
175 
176  if (_bitpos == 0)
177  {
178  _bitpos = 8;
179  append((uint8 *)&_curbitval, sizeof(_curbitval));
180  _curbitval = 0;
181  }
182 
183  return (bit != 0);
184  }
uint8 _curbitval
Definition: ByteBuffer.h:706
void append(T value)
Definition: ByteBuffer.h:143
size_t _bitpos
Definition: ByteBuffer.h:705
uint8_t uint8
Definition: Define.h:152

+ Here is the call graph for this function:

template<typename T >
void ByteBuffer::WriteBits ( value,
int32  bits 
)
inline
199  {
200  for (int32 i = bits - 1; i >= 0; --i)
201  WriteBit((value >> i) & 1);
202  }
bool WriteBit(uint32 bit)
Definition: ByteBuffer.h:170
int32_t int32
Definition: Define.h:146
uint16 bits() const
Returns the underlying bits in this representation. Equivalent to:
Definition: unorm16.h:89
const FieldDescriptor value
Definition: descriptor.h:1522

+ Here is the caller graph for this function:

void ByteBuffer::WriteByteSeq ( uint8  b)
inline
222  {
223  if (b != 0)
224  append<uint8>(b ^ 1);
225  }

+ Here is the caller graph for this function:

void ByteBuffer::WriteString ( std::string const str)
inline

Method for writing strings that have their length sent separately in packet without null-terminating the string

541  {
542  if (size_t len = str.length())
543  append(str.c_str(), len);
544  }
void append(T value)
Definition: ByteBuffer.h:143

+ Here is the call graph for this function:

+ Here is the caller graph for this function:

void ByteBuffer::WriteString ( char const str,
size_t  len 
)
inline
547  {
548  if (len)
549  append(str, len);
550  }
void append(T value)
Definition: ByteBuffer.h:143

+ Here is the call graph for this function:

Member Data Documentation

size_t ByteBuffer::_bitpos
protected
uint8 ByteBuffer::_curbitval
protected
size_t ByteBuffer::_rpos
protected
std::vector<uint8> ByteBuffer::_storage
protected
size_t ByteBuffer::_wpos
protected
size_t const ByteBuffer::DEFAULT_SIZE = 0x1000
static
uint8 const ByteBuffer::InitialBitPos = 8
static

The documentation for this class was generated from the following files: