TrinityCore
ByteBuffer Class Reference

#include <ByteBuffer.h>

+ Inheritance diagram for ByteBuffer:

Classes

struct  Reserve
 
struct  Resize
 

Public Member Functions

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

Static Public Attributes

static constexpr size_t DEFAULT_SIZE = 0x1000
 
static constexpr uint8 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
 
void PutBits (std::size_t pos, std::size_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<< (std::string_view value)
 
ByteBufferoperator<< (std::string const &str)
 
ByteBufferoperator<< (char const *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 const & operator[] (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 , typename Underlying = T>
read ()
 
template<typename T , typename Underlying = T>
read (size_t pos) const
 
template<class T >
void read (T *dest, size_t count)
 
void read (uint8 *dest, size_t len)
 
template<size_t Size>
void read (std::array< uint8, Size > &arr)
 
void ReadPackedUInt64 (uint64 &guid)
 
void ReadPackedUInt64 (uint8 mask, uint64 &value)
 
void WriteString (std::string const &str)
 
void WriteString (std::string_view str)
 
void WriteString (char const *str, size_t len)
 
std::string_view ReadCString (bool requireValidUtf8=true)
 
std::string_view ReadString (uint32 length, bool requireValidUtf8=true)
 
uint8contents ()
 
uint8 const * contents () const
 
size_t size () const
 
bool empty () const
 
void resize (size_t newsize)
 
void reserve (size_t ressize)
 
void shrink_to_fit ()
 
void append (const char *src, size_t cnt)
 
template<class T >
void append (const T *src, size_t cnt)
 
void append (uint8 const *src, size_t cnt)
 
void append (ByteBuffer const &buffer)
 
template<size_t Size>
void append (std::array< uint8, Size > const &arr)
 
void appendPackXYZ (float x, float y, float z)
 
void AppendPackedUInt64 (uint64 guid)
 
void put (size_t pos, uint8 const *src, size_t cnt)
 
void print_storage () const
 
void textlike () const
 
void hexlike () const
 
static size_t PackUInt64 (uint64 value, uint8 *mask, uint8 *result)
 

Detailed Description

Definition at line 55 of file ByteBuffer.h.

Constructor & Destructor Documentation

◆ ByteBuffer() [1/6]

ByteBuffer::ByteBuffer ( )
inline

Definition at line 62 of file ByteBuffer.h.

◆ ByteBuffer() [2/6]

ByteBuffer::ByteBuffer ( size_t  size,
Reserve   
)
inline

Definition at line 71 of file ByteBuffer.h.

+ Here is the call graph for this function:

◆ ByteBuffer() [3/6]

ByteBuffer::ByteBuffer ( size_t  size,
Resize   
)
inline

Definition at line 76 of file ByteBuffer.h.

+ Here is the call graph for this function:

◆ ByteBuffer() [4/6]

ByteBuffer::ByteBuffer ( ByteBuffer &&  buf)
inlinenoexcept

Definition at line 81 of file ByteBuffer.h.

◆ ByteBuffer() [5/6]

ByteBuffer::ByteBuffer ( ByteBuffer const &  right)
default

◆ ByteBuffer() [6/6]

ByteBuffer::ByteBuffer ( MessageBuffer &&  buffer)

Definition at line 28 of file ByteBuffer.cpp.

◆ ~ByteBuffer()

virtual ByteBuffer::~ByteBuffer ( )
virtualdefault

Member Function Documentation

◆ append() [1/6]

void ByteBuffer::append ( ByteBuffer const &  buffer)
inline

Definition at line 564 of file ByteBuffer.h.

+ Here is the call graph for this function:

◆ append() [2/6]

void ByteBuffer::append ( const char *  src,
size_t  cnt 
)
inline

Definition at line 551 of file ByteBuffer.h.

◆ append() [3/6]

template<class T >
void ByteBuffer::append ( const T *  src,
size_t  cnt 
)
inline

Definition at line 557 of file ByteBuffer.h.

◆ append() [4/6]

template<size_t Size>
void ByteBuffer::append ( std::array< uint8, Size > const &  arr)
inline

Definition at line 571 of file ByteBuffer.h.

+ Here is the call graph for this function:

◆ append() [5/6]

template<typename T >
void ByteBuffer::append ( value)
inline

Definition at line 137 of file ByteBuffer.h.

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ append() [6/6]

void ByteBuffer::append ( uint8 const *  src,
size_t  cnt 
)

Definition at line 94 of file ByteBuffer.cpp.

+ Here is the call graph for this function:

◆ AppendPackedUInt64()

void ByteBuffer::AppendPackedUInt64 ( uint64  guid)
inline

Definition at line 586 of file ByteBuffer.h.

◆ appendPackXYZ()

void ByteBuffer::appendPackXYZ ( float  x,
float  y,
float  z 
)
inline

Definition at line 577 of file ByteBuffer.h.

+ Here is the caller graph for this function:

◆ bitwpos() [1/2]

size_t ByteBuffer::bitwpos ( ) const
inline

Returns position of last written bit.

Definition at line 415 of file ByteBuffer.h.

◆ bitwpos() [2/2]

size_t ByteBuffer::bitwpos ( size_t  newPos)
inline

Definition at line 417 of file ByteBuffer.h.

◆ clear()

void ByteBuffer::clear ( )
inline

Definition at line 127 of file ByteBuffer.h.

+ Here is the caller graph for this function:

◆ contents() [1/2]

uint8 * ByteBuffer::contents ( )
inline

Definition at line 516 of file ByteBuffer.h.

+ Here is the caller graph for this function:

◆ contents() [2/2]

uint8 const * ByteBuffer::contents ( ) const
inline

Definition at line 523 of file ByteBuffer.h.

◆ empty()

bool ByteBuffer::empty ( ) const
inline

Definition at line 531 of file ByteBuffer.h.

+ Here is the caller graph for this function:

◆ FlushBits()

void ByteBuffer::FlushBits ( )
inline

Definition at line 149 of file ByteBuffer.h.

◆ HasUnfinishedBitPack()

bool ByteBuffer::HasUnfinishedBitPack ( ) const
inline

Definition at line 144 of file ByteBuffer.h.

+ Here is the caller graph for this function:

◆ hexlike()

void ByteBuffer::hexlike ( ) const

Definition at line 177 of file ByteBuffer.cpp.

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ Move()

std::vector< uint8 > && ByteBuffer::Move ( )
inlinenoexcept

Definition at line 88 of file ByteBuffer.h.

◆ operator<<() [1/13]

ByteBuffer & ByteBuffer::operator<< ( char const *  str)
inline

Definition at line 310 of file ByteBuffer.h.

+ Here is the call graph for this function:

◆ operator<<() [2/13]

ByteBuffer & ByteBuffer::operator<< ( double  value)
inline

Definition at line 291 of file ByteBuffer.h.

◆ operator<<() [3/13]

ByteBuffer & ByteBuffer::operator<< ( float  value)
inline

Definition at line 285 of file ByteBuffer.h.

◆ operator<<() [4/13]

ByteBuffer & ByteBuffer::operator<< ( int16  value)
inline

Definition at line 266 of file ByteBuffer.h.

◆ operator<<() [5/13]

ByteBuffer & ByteBuffer::operator<< ( int32  value)
inline

Definition at line 272 of file ByteBuffer.h.

◆ operator<<() [6/13]

ByteBuffer & ByteBuffer::operator<< ( int64  value)
inline

Definition at line 278 of file ByteBuffer.h.

◆ operator<<() [7/13]

ByteBuffer & ByteBuffer::operator<< ( int8  value)
inline

Definition at line 260 of file ByteBuffer.h.

◆ operator<<() [8/13]

ByteBuffer & ByteBuffer::operator<< ( std::string const &  str)
inline

Definition at line 305 of file ByteBuffer.h.

+ Here is the call graph for this function:

◆ operator<<() [9/13]

ByteBuffer & ByteBuffer::operator<< ( std::string_view  value)
inline

Definition at line 297 of file ByteBuffer.h.

◆ operator<<() [10/13]

ByteBuffer & ByteBuffer::operator<< ( uint16  value)
inline

Definition at line 241 of file ByteBuffer.h.

◆ operator<<() [11/13]

ByteBuffer & ByteBuffer::operator<< ( uint32  value)
inline

Definition at line 247 of file ByteBuffer.h.

◆ operator<<() [12/13]

ByteBuffer & ByteBuffer::operator<< ( uint64  value)
inline

Definition at line 253 of file ByteBuffer.h.

◆ operator<<() [13/13]

ByteBuffer & ByteBuffer::operator<< ( uint8  value)
inline

Definition at line 235 of file ByteBuffer.h.

◆ operator=() [1/2]

ByteBuffer & ByteBuffer::operator= ( ByteBuffer &&  right)
inlinenoexcept

Definition at line 111 of file ByteBuffer.h.

◆ operator=() [2/2]

ByteBuffer & ByteBuffer::operator= ( ByteBuffer const &  right)
inline

Definition at line 97 of file ByteBuffer.h.

+ Here is the caller graph for this function:

◆ operator>>() [1/12]

ByteBuffer & ByteBuffer::operator>> ( bool &  value)
inline

Definition at line 315 of file ByteBuffer.h.

◆ operator>>() [2/12]

ByteBuffer & ByteBuffer::operator>> ( double &  value)

Definition at line 50 of file ByteBuffer.cpp.

◆ operator>>() [3/12]

ByteBuffer & ByteBuffer::operator>> ( float &  value)

Definition at line 42 of file ByteBuffer.cpp.

◆ operator>>() [4/12]

ByteBuffer & ByteBuffer::operator>> ( int16 value)
inline

Definition at line 352 of file ByteBuffer.h.

◆ operator>>() [5/12]

ByteBuffer & ByteBuffer::operator>> ( int32 value)
inline

Definition at line 358 of file ByteBuffer.h.

◆ operator>>() [6/12]

ByteBuffer & ByteBuffer::operator>> ( int64 value)
inline

Definition at line 364 of file ByteBuffer.h.

◆ operator>>() [7/12]

ByteBuffer & ByteBuffer::operator>> ( int8 value)
inline

Definition at line 346 of file ByteBuffer.h.

◆ operator>>() [8/12]

ByteBuffer & ByteBuffer::operator>> ( std::string &  value)
inline

Definition at line 373 of file ByteBuffer.h.

◆ operator>>() [9/12]

ByteBuffer & ByteBuffer::operator>> ( uint16 value)
inline

Definition at line 327 of file ByteBuffer.h.

◆ operator>>() [10/12]

ByteBuffer & ByteBuffer::operator>> ( uint32 value)
inline

Definition at line 333 of file ByteBuffer.h.

◆ operator>>() [11/12]

ByteBuffer & ByteBuffer::operator>> ( uint64 value)
inline

Definition at line 339 of file ByteBuffer.h.

◆ operator>>() [12/12]

ByteBuffer & ByteBuffer::operator>> ( uint8 value)
inline

Definition at line 321 of file ByteBuffer.h.

◆ operator[]() [1/2]

uint8 & ByteBuffer::operator[] ( size_t const  pos)
inline

Definition at line 379 of file ByteBuffer.h.

+ Here is the call graph for this function:

◆ operator[]() [2/2]

uint8 const & ByteBuffer::operator[] ( size_t const  pos) const
inline

Definition at line 386 of file ByteBuffer.h.

+ Here is the call graph for this function:

◆ PackUInt64()

static size_t ByteBuffer::PackUInt64 ( uint64  value,
uint8 mask,
uint8 result 
)
inlinestatic

Definition at line 599 of file ByteBuffer.h.

◆ print_storage()

void ByteBuffer::print_storage ( ) const

Definition at line 146 of file ByteBuffer.cpp.

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ put() [1/2]

void ByteBuffer::put ( size_t  pos,
uint8 const *  src,
size_t  cnt 
)

Definition at line 121 of file ByteBuffer.cpp.

+ Here is the call graph for this function:

◆ put() [2/2]

template<typename T >
void ByteBuffer::put ( std::size_t  pos,
value 
)
inline

Definition at line 214 of file ByteBuffer.h.

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ PutBits()

void ByteBuffer::PutBits ( std::size_t  pos,
std::size_t  value,
uint32  bitCount 
)

Definition at line 130 of file ByteBuffer.cpp.

+ Here is the call graph for this function:

◆ read() [1/5]

template<typename T , typename Underlying = T>
T ByteBuffer::read ( )
inline

Definition at line 437 of file ByteBuffer.h.

+ Here is the caller graph for this function:

◆ read() [2/5]

template<typename T , typename Underlying = T>
T ByteBuffer::read ( size_t  pos) const
inline

Definition at line 446 of file ByteBuffer.h.

+ Here is the call graph for this function:

◆ read() [3/5]

template<size_t Size>
void ByteBuffer::read ( std::array< uint8, Size > &  arr)
inline

Definition at line 474 of file ByteBuffer.h.

+ Here is the call graph for this function:

◆ read() [4/5]

template<class T >
void ByteBuffer::read ( T *  dest,
size_t  count 
)
inline

Definition at line 457 of file ByteBuffer.h.

◆ read() [5/5]

void ByteBuffer::read ( uint8 dest,
size_t  len 
)
inline

Definition at line 463 of file ByteBuffer.h.

+ Here is the call graph for this function:

◆ read_skip() [1/4]

template<typename T >
void ByteBuffer::read_skip ( )
inline

Definition at line 425 of file ByteBuffer.h.

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ read_skip() [2/4]

template<>
void ByteBuffer::read_skip ( )
inline

Definition at line 640 of file ByteBuffer.h.

+ Here is the call graph for this function:

◆ read_skip() [3/4]

template<>
void ByteBuffer::read_skip ( )
inline

Definition at line 646 of file ByteBuffer.h.

◆ read_skip() [4/4]

void ByteBuffer::read_skip ( size_t  skip)
inline

Definition at line 427 of file ByteBuffer.h.

+ Here is the call graph for this function:

◆ ReadBit()

bool ByteBuffer::ReadBit ( )
inline

Definition at line 185 of file ByteBuffer.h.

+ Here is the caller graph for this function:

◆ ReadBits()

uint32 ByteBuffer::ReadBits ( int32  bits)
inline

Definition at line 203 of file ByteBuffer.h.

+ Here is the caller graph for this function:

◆ ReadCString()

std::string_view ByteBuffer::ReadCString ( bool  requireValidUtf8 = true)

Definition at line 58 of file ByteBuffer.cpp.

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ ReadPackedUInt64() [1/2]

void ByteBuffer::ReadPackedUInt64 ( uint64 guid)
inline

Definition at line 479 of file ByteBuffer.h.

◆ ReadPackedUInt64() [2/2]

void ByteBuffer::ReadPackedUInt64 ( uint8  mask,
uint64 value 
)
inline

Definition at line 485 of file ByteBuffer.h.

◆ ReadString()

std::string_view ByteBuffer::ReadString ( uint32  length,
bool  requireValidUtf8 = true 
)

Definition at line 78 of file ByteBuffer.cpp.

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ reserve()

void ByteBuffer::reserve ( size_t  ressize)
inline

Definition at line 540 of file ByteBuffer.h.

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ ResetBitPos()

void ByteBuffer::ResetBitPos ( )
inline

Definition at line 160 of file ByteBuffer.h.

+ Here is the caller graph for this function:

◆ resize()

void ByteBuffer::resize ( size_t  newsize)
inline

Definition at line 533 of file ByteBuffer.h.

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ rfinish()

void ByteBuffer::rfinish ( )
inline

Definition at line 401 of file ByteBuffer.h.

+ Here is the caller graph for this function:

◆ rpos() [1/2]

size_t ByteBuffer::rpos ( ) const
inline

Definition at line 393 of file ByteBuffer.h.

+ Here is the caller graph for this function:

◆ rpos() [2/2]

size_t ByteBuffer::rpos ( size_t  rpos_)
inline

Definition at line 395 of file ByteBuffer.h.

◆ shrink_to_fit()

void ByteBuffer::shrink_to_fit ( )
inline

Definition at line 546 of file ByteBuffer.h.

◆ size()

size_t ByteBuffer::size ( ) const
inline

Definition at line 530 of file ByteBuffer.h.

+ Here is the caller graph for this function:

◆ textlike()

void ByteBuffer::textlike ( ) const

Definition at line 160 of file ByteBuffer.cpp.

+ Here is the call graph for this function:

◆ wpos() [1/2]

size_t ByteBuffer::wpos ( ) const
inline

Definition at line 406 of file ByteBuffer.h.

+ Here is the caller graph for this function:

◆ wpos() [2/2]

size_t ByteBuffer::wpos ( size_t  wpos_)
inline

Definition at line 408 of file ByteBuffer.h.

◆ WriteBit()

bool ByteBuffer::WriteBit ( bool  bit)
inline

Definition at line 169 of file ByteBuffer.h.

+ Here is the caller graph for this function:

◆ WriteBits()

void ByteBuffer::WriteBits ( std::size_t  value,
int32  bits 
)
inline

Definition at line 197 of file ByteBuffer.h.

+ Here is the caller graph for this function:

◆ WriteString() [1/3]

void ByteBuffer::WriteString ( char const *  str,
size_t  len 
)
inline

Definition at line 506 of file ByteBuffer.h.

◆ WriteString() [2/3]

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

Definition at line 494 of file ByteBuffer.h.

+ Here is the caller graph for this function:

◆ WriteString() [3/3]

void ByteBuffer::WriteString ( std::string_view  str)
inline

Definition at line 500 of file ByteBuffer.h.

Member Data Documentation

◆ _bitpos

size_t ByteBuffer::_bitpos
protected

Definition at line 628 of file ByteBuffer.h.

◆ _curbitval

uint8 ByteBuffer::_curbitval
protected

Definition at line 629 of file ByteBuffer.h.

◆ _rpos

size_t ByteBuffer::_rpos
protected

Definition at line 628 of file ByteBuffer.h.

◆ _storage

std::vector<uint8> ByteBuffer::_storage
protected

Definition at line 630 of file ByteBuffer.h.

◆ _wpos

size_t ByteBuffer::_wpos
protected

Definition at line 628 of file ByteBuffer.h.

◆ DEFAULT_SIZE

constexpr size_t ByteBuffer::DEFAULT_SIZE = 0x1000
staticconstexpr

Definition at line 58 of file ByteBuffer.h.

◆ InitialBitPos

constexpr uint8 ByteBuffer::InitialBitPos = 8
staticconstexpr

Definition at line 59 of file ByteBuffer.h.


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