AzerothCore 3.3.5a
OpenSource WoW Emulator
Loading...
Searching...
No Matches
MessageBuffer Class Reference

#include "MessageBuffer.h"

Public Member Functions

 MessageBuffer ()
 
 MessageBuffer (std::size_t initialSize)
 
 MessageBuffer (MessageBuffer const &right)
 
 MessageBuffer (MessageBuffer &&right) noexcept
 
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) noexcept
 

Private Types

using size_type = std::vector< uint8 >::size_type
 

Private Attributes

size_type _wpos {0}
 
size_type _rpos {0}
 
std::vector< uint8_storage
 

Detailed Description

Member Typedef Documentation

◆ size_type

using MessageBuffer::size_type = std::vector<uint8>::size_type
private

Constructor & Destructor Documentation

◆ MessageBuffer() [1/4]

MessageBuffer::MessageBuffer ( )
inline
30 : _storage()
31 {
32 _storage.resize(4096);
33 }
std::vector< uint8 > _storage
Definition: MessageBuffer.h:137

References _storage.

◆ MessageBuffer() [2/4]

MessageBuffer::MessageBuffer ( std::size_t  initialSize)
inlineexplicit
35 : _wpos(0), _rpos(0), _storage()
36 {
37 _storage.resize(initialSize);
38 }
size_type _rpos
Definition: MessageBuffer.h:136
size_type _wpos
Definition: MessageBuffer.h:135

References _storage.

◆ MessageBuffer() [3/4]

MessageBuffer::MessageBuffer ( MessageBuffer const &  right)
inline
40 :
41 _wpos(right._wpos), _rpos(right._rpos), _storage(right._storage) { }

◆ MessageBuffer() [4/4]

MessageBuffer::MessageBuffer ( MessageBuffer &&  right)
inlinenoexcept
43 :
44 _wpos(right._wpos), _rpos(right._rpos), _storage(right.Move()) { }
std::vector< uint8 > && Move()
Definition: MessageBuffer.h:102

Member Function Documentation

◆ EnsureFreeSpace()

void MessageBuffer::EnsureFreeSpace ( )
inline
85 {
86 // resize buffer if it's already full
87 if (GetRemainingSpace() == 0)
88 {
89 _storage.resize(_storage.size() * 3 / 2);
90 }
91 }
size_type GetRemainingSpace() const
Definition: MessageBuffer.h:65

References _storage, and GetRemainingSpace().

Referenced by Socket< T >::AsyncRead(), Socket< T >::AsyncReadProxyHeader(), and Socket< T >::AsyncReadWithCallback().

◆ GetActiveSize()

◆ GetBasePointer()

uint8 * MessageBuffer::GetBasePointer ( )
inline
57{ return _storage.data(); }

References _storage.

Referenced by GetReadPointer(), GetWritePointer(), and Normalize().

◆ GetBufferSize()

size_type MessageBuffer::GetBufferSize ( ) const
inline
66{ return _storage.size(); }

References _storage.

◆ GetReadPointer()

◆ GetRemainingSpace()

◆ GetWritePointer()

uint8 * MessageBuffer::GetWritePointer ( )
inline

◆ Move()

std::vector< uint8 > && MessageBuffer::Move ( )
inline
103 {
104 _wpos = 0;
105 _rpos = 0;
106
107 return std::move(_storage);
108 }

References _rpos, _storage, and _wpos.

◆ Normalize()

void MessageBuffer::Normalize ( )
inline
70 {
71 if (_rpos)
72 {
73 if (_rpos != _wpos)
74 {
76 }
77
78 _wpos -= _rpos;
79 _rpos = 0;
80 }
81 }
uint8 * GetReadPointer()
Definition: MessageBuffer.h:58
size_type GetActiveSize() const
Definition: MessageBuffer.h:64

References _rpos, _wpos, GetActiveSize(), GetBasePointer(), and GetReadPointer().

Referenced by Socket< T >::AsyncRead(), Socket< T >::AsyncReadProxyHeader(), and Socket< T >::AsyncReadWithCallback().

◆ operator=() [1/2]

MessageBuffer & MessageBuffer::operator= ( MessageBuffer &&  right)
inlinenoexcept
123 {
124 if (this != &right)
125 {
126 _wpos = right._wpos;
127 _rpos = right._rpos;
128 _storage = right.Move();
129 }
130
131 return *this;
132 }

References _rpos, _storage, and _wpos.

◆ operator=() [2/2]

MessageBuffer & MessageBuffer::operator= ( MessageBuffer const &  right)
inline
111 {
112 if (this != &right)
113 {
114 _wpos = right._wpos;
115 _rpos = right._rpos;
116 _storage = right._storage;
117 }
118
119 return *this;
120 }

References _rpos, _storage, and _wpos.

◆ ReadCompleted()

void MessageBuffer::ReadCompleted ( size_type  bytes)
inline

◆ Reset()

void MessageBuffer::Reset ( )
inline
47 {
48 _wpos = 0;
49 _rpos = 0;
50 }

References _rpos, and _wpos.

Referenced by AuthSession::ReadHandler(), and WorldSocket::ReadHandler().

◆ Resize()

void MessageBuffer::Resize ( size_type  bytes)
inline

◆ Write()

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

References GetWritePointer(), and WriteCompleted().

Referenced by WorldSocket::ReadHandler(), AuthSession::SendPacket(), and WorldSocket::Update().

◆ WriteCompleted()

void MessageBuffer::WriteCompleted ( size_type  bytes)
inline

Member Data Documentation

◆ _rpos

size_type MessageBuffer::_rpos {0}
private

◆ _storage

std::vector<uint8> MessageBuffer::_storage
private

◆ _wpos