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

#include <MessageBuffer.h>

Public Member Functions

 MessageBuffer ()
 
 MessageBuffer (std::size_t initialSize)
 
 MessageBuffer (MessageBuffer const &right)
 
 MessageBuffer (MessageBuffer &&right)
 
void Reset ()
 
void Resize (size_type bytes)
 
uint8GetBasePointer ()
 
uint8GetReadPointer ()
 
uint8GetWritePointer ()
 
void ReadCompleted (size_type bytes)
 
void WriteCompleted (size_type bytes)
 
size_type GetActiveSize () const
 
size_type GetRemainingSpace () const
 
size_type GetBufferSize () const
 
void Normalize ()
 
void EnsureFreeSpace ()
 
void Write (void const *data, std::size_t size)
 
std::vector< uint8 > && Move ()
 
MessageBufferoperator= (MessageBuffer const &right)
 
MessageBufferoperator= (MessageBuffer &&right)
 

Private Types

typedef std::vector< uint8 >
::size_type 
size_type
 

Private Attributes

size_type _wpos
 
size_type _rpos
 
std::vector< uint8_storage
 

Member Typedef Documentation

typedef std::vector<uint8>::size_type MessageBuffer::size_type
private

Constructor & Destructor Documentation

MessageBuffer::MessageBuffer ( )
inline
29  : _wpos(0), _rpos(0), _storage()
30  {
31  _storage.resize(4096);
32  }
std::vector< uint8 > _storage
Definition: MessageBuffer.h:135
size_type _wpos
Definition: MessageBuffer.h:133
size_type _rpos
Definition: MessageBuffer.h:134
MessageBuffer::MessageBuffer ( std::size_t  initialSize)
inlineexplicit
34  : _wpos(0), _rpos(0), _storage()
35  {
36  _storage.resize(initialSize);
37  }
std::vector< uint8 > _storage
Definition: MessageBuffer.h:135
size_type _wpos
Definition: MessageBuffer.h:133
size_type _rpos
Definition: MessageBuffer.h:134
MessageBuffer::MessageBuffer ( MessageBuffer const right)
inline
39  : _wpos(right._wpos), _rpos(right._rpos), _storage(right._storage)
40  {
41  }
std::vector< uint8 > _storage
Definition: MessageBuffer.h:135
size_type _wpos
Definition: MessageBuffer.h:133
size_type _rpos
Definition: MessageBuffer.h:134
MessageBuffer::MessageBuffer ( MessageBuffer &&  right)
inline
43 : _wpos(right._wpos), _rpos(right._rpos), _storage(right.Move()) { }
std::vector< uint8 > && Move()
Definition: MessageBuffer.h:101
std::vector< uint8 > _storage
Definition: MessageBuffer.h:135
size_type _wpos
Definition: MessageBuffer.h:133
size_type _rpos
Definition: MessageBuffer.h:134

Member Function Documentation

void MessageBuffer::EnsureFreeSpace ( )
inline
86  {
87  // resize buffer if it's already full
88  if (GetRemainingSpace() == 0)
89  _storage.resize(_storage.size() * 3 / 2);
90  }
size_type GetRemainingSpace() const
Definition: MessageBuffer.h:68
std::vector< uint8 > _storage
Definition: MessageBuffer.h:135

+ Here is the call graph for this function:

+ Here is the caller graph for this function:

size_type MessageBuffer::GetActiveSize ( ) const
inline
66 { return _wpos - _rpos; }
size_type _wpos
Definition: MessageBuffer.h:133
size_type _rpos
Definition: MessageBuffer.h:134

+ Here is the caller graph for this function:

uint8* MessageBuffer::GetBasePointer ( )
inline
56 { return _storage.data(); }
std::vector< uint8 > _storage
Definition: MessageBuffer.h:135

+ Here is the caller graph for this function:

size_type MessageBuffer::GetBufferSize ( ) const
inline
70 { return _storage.size(); }
std::vector< uint8 > _storage
Definition: MessageBuffer.h:135
uint8* MessageBuffer::GetReadPointer ( )
inline
58 { return GetBasePointer() + _rpos; }
uint8 * GetBasePointer()
Definition: MessageBuffer.h:56
size_type _rpos
Definition: MessageBuffer.h:134

+ Here is the call graph for this function:

+ Here is the caller graph for this function:

size_type MessageBuffer::GetRemainingSpace ( ) const
inline
68 { return _storage.size() - _wpos; }
std::vector< uint8 > _storage
Definition: MessageBuffer.h:135
size_type _wpos
Definition: MessageBuffer.h:133

+ Here is the caller graph for this function:

uint8* MessageBuffer::GetWritePointer ( )
inline
60 { return GetBasePointer() + _wpos; }
uint8 * GetBasePointer()
Definition: MessageBuffer.h:56
size_type _wpos
Definition: MessageBuffer.h:133

+ Here is the call graph for this function:

+ Here is the caller graph for this function:

std::vector<uint8>&& MessageBuffer::Move ( )
inline
102  {
103  _wpos = 0;
104  _rpos = 0;
105  return std::move(_storage);
106  }
std::vector< uint8 > _storage
Definition: MessageBuffer.h:135
size_type _wpos
Definition: MessageBuffer.h:133
size_type _rpos
Definition: MessageBuffer.h:134
void MessageBuffer::Normalize ( )
inline
74  {
75  if (_rpos)
76  {
77  if (_rpos != _wpos)
79  _wpos -= _rpos;
80  _rpos = 0;
81  }
82  }
uint8 * GetBasePointer()
Definition: MessageBuffer.h:56
size_type _wpos
Definition: MessageBuffer.h:133
size_type GetActiveSize() const
Definition: MessageBuffer.h:66
size_type _rpos
Definition: MessageBuffer.h:134
uint8 * GetReadPointer()
Definition: MessageBuffer.h:58

+ Here is the call graph for this function:

+ Here is the caller graph for this function:

MessageBuffer& MessageBuffer::operator= ( MessageBuffer const right)
inline
109  {
110  if (this != &right)
111  {
112  _wpos = right._wpos;
113  _rpos = right._rpos;
114  _storage = right._storage;
115  }
116 
117  return *this;
118  }
std::vector< uint8 > _storage
Definition: MessageBuffer.h:135
size_type _wpos
Definition: MessageBuffer.h:133
size_type _rpos
Definition: MessageBuffer.h:134
MessageBuffer& MessageBuffer::operator= ( MessageBuffer &&  right)
inline
121  {
122  if (this != &right)
123  {
124  _wpos = right._wpos;
125  _rpos = right._rpos;
126  _storage = right.Move();
127  }
128 
129  return *this;
130  }
std::vector< uint8 > && Move()
Definition: MessageBuffer.h:101
std::vector< uint8 > _storage
Definition: MessageBuffer.h:135
size_type _wpos
Definition: MessageBuffer.h:133
size_type _rpos
Definition: MessageBuffer.h:134
void MessageBuffer::ReadCompleted ( size_type  bytes)
inline
62 { _rpos += bytes; }
size_type _rpos
Definition: MessageBuffer.h:134

+ Here is the caller graph for this function:

void MessageBuffer::Reset ( )
inline
46  {
47  _wpos = 0;
48  _rpos = 0;
49  }
size_type _wpos
Definition: MessageBuffer.h:133
size_type _rpos
Definition: MessageBuffer.h:134

+ Here is the caller graph for this function:

void MessageBuffer::Resize ( size_type  bytes)
inline
52  {
53  _storage.resize(bytes);
54  }
std::vector< uint8 > _storage
Definition: MessageBuffer.h:135

+ Here is the caller graph for this function:

void MessageBuffer::Write ( void const data,
std::size_t  size 
)
inline
93  {
94  if (size)
95  {
96  memcpy(GetWritePointer(), data, size);
97  WriteCompleted(size);
98  }
99  }
uint8 * GetWritePointer()
Definition: MessageBuffer.h:60
void WriteCompleted(size_type bytes)
Definition: MessageBuffer.h:64

+ Here is the call graph for this function:

+ Here is the caller graph for this function:

void MessageBuffer::WriteCompleted ( size_type  bytes)
inline
64 { _wpos += bytes; }
size_type _wpos
Definition: MessageBuffer.h:133

+ Here is the caller graph for this function:

Member Data Documentation

size_type MessageBuffer::_rpos
private
std::vector<uint8> MessageBuffer::_storage
private
size_type MessageBuffer::_wpos
private

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