Horizon Official Technical Documentation
ByteBuffer Class Reference

#include <ByteBuffer.hpp>

Public Member Functions

 ByteBuffer ()
 
 ByteBuffer (size_t reserve)
 
 ByteBuffer (ByteBuffer &&buf)
 
 ByteBuffer (ByteBuffer &buf, size_t len)
 
 ByteBuffer (ByteBuffer const &right)
 
ByteBufferoperator= (ByteBuffer const &right)
 
virtual ~ByteBuffer ()
 
void clear ()
 
void reset ()
 
template<typename T >
void append (T value)
 
template<typename T >
void put (size_t pos, T value)
 
ByteBufferoperator<< (uint8_t value)
 
ByteBufferoperator<< (uint16_t value)
 
ByteBufferoperator<< (uint32_t value)
 
ByteBufferoperator<< (uint64_t value)
 
ByteBufferoperator<< (int8_t value)
 
ByteBufferoperator<< (int16_t value)
 
ByteBufferoperator<< (int32_t value)
 
ByteBufferoperator<< (int64_t value)
 
ByteBufferoperator<< (float value)
 
ByteBufferoperator<< (double value)
 
ByteBufferoperator>> (bool &value)
 
ByteBufferoperator>> (uint8_t &value)
 
ByteBufferoperator>> (uint16_t &value)
 
ByteBufferoperator>> (uint32_t &value)
 
ByteBufferoperator>> (uint64_t &value)
 
ByteBufferoperator>> (int8_t &value)
 
ByteBufferoperator>> (int16_t &value)
 
ByteBufferoperator>> (int32_t &value)
 
ByteBufferoperator>> (int64_t &value)
 
ByteBufferoperator>> (float &value)
 
ByteBufferoperator>> (double &value)
 
uint8_t & operator[] (size_t const pos)
 
uint8_t const & operator[] (size_t const pos) const
 
size_t rpos () const
 
size_t rpos (size_t rpos_)
 
uint8_t * contents ()
 
uint8_t const * contents () const
 
void finish_reading ()
 
void read_completed (size_t bytes)
 
void write_completed (size_t bytes)
 
size_t wpos () const
 
uint8_t * get_base_pointer ()
 
uint8_t * get_read_pointer ()
 
uint8_t * get_write_pointer ()
 
std::string to_string ()
 
size_t maximum_length () const
 
size_t active_length () const
 
size_t remaining_space () const
 
bool is_empty () const
 
void flush ()
 
void ensure_free_space ()
 
void resize (size_t new_size)
 
void reserve (size_t ressize)
 
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 (char *dest, size_t len)
 
void read (ByteBuffer &buf, size_t len)
 
void append (const char *src, size_t size)
 
void append (std::string string)
 
template<class T >
void append (const T *src, size_t size)
 
template<class T , class SubT >
void append (const T *t, size_t t_size, const SubT *sub_t, int count)
 
void append (const uint8_t *src, size_t cnt)
 
void append (const ByteBuffer &buffer)
 
void put (size_t pos, const uint8_t *src, size_t cnt)
 
void print_storage () const
 
void textlike () const
 
void hexlike () const
 
template<typename SizeT = uint16_t, typename std::enable_if< std::is_integral< SizeT >::value >::type * = nullptr>
void emplace_size (std::size_t pos=2)
 
template<>
void read_skip ()
 

Static Public Attributes

static const size_t DEFAULT_SIZE = 0x1000
 

Protected Attributes

size_t _rpos {0}
 
size_t _wpos {0}
 
std::vector< uint8_t > _storage
 

Constructor & Destructor Documentation

◆ ByteBuffer() [1/5]

ByteBuffer::ByteBuffer ( )
inline
84 : _rpos(0), _wpos(0)
85 {
86 _storage.reserve(DEFAULT_SIZE);
87 }
size_t _wpos
Definition: ByteBuffer.hpp:494
static const size_t DEFAULT_SIZE
Definition: ByteBuffer.hpp:80
std::vector< uint8_t > _storage
Definition: ByteBuffer.hpp:495
size_t _rpos
Definition: ByteBuffer.hpp:494

References _storage, and DEFAULT_SIZE.

◆ ByteBuffer() [2/5]

ByteBuffer::ByteBuffer ( size_t  reserve)
inline
90 : _rpos(0), _wpos(0)
91 {
92 _storage.reserve(reserve);
93 }
void reserve(size_t ressize)
Definition: ByteBuffer.hpp:362

References _storage, and reserve().

+ Here is the call graph for this function:

◆ ByteBuffer() [3/5]

ByteBuffer::ByteBuffer ( ByteBuffer &&  buf)
inline
96 : _rpos(buf._rpos), _wpos(buf._wpos), _storage(std::move(buf._storage))
97 { }

◆ ByteBuffer() [4/5]

ByteBuffer::ByteBuffer ( ByteBuffer buf,
size_t  len 
)
inline
100 : _rpos(0)
101 {
102 _storage.resize(len);
103 // copy len bytes from buf
104 std::memcpy(&_storage[_wpos], buf.contents(), len);
105 _wpos = len;
106 buf._rpos += len;
107 }
uint8_t * contents()
Definition: ByteBuffer.hpp:306

References _rpos, _storage, _wpos, and contents().

+ Here is the call graph for this function:

◆ ByteBuffer() [5/5]

ByteBuffer::ByteBuffer ( ByteBuffer const &  right)
inline
110 : _rpos(right._rpos), _wpos(right._wpos), _storage(right._storage)
111 { }

◆ ~ByteBuffer()

virtual ByteBuffer::~ByteBuffer ( )
inlinevirtual
126 { }

Member Function Documentation

◆ active_length()

◆ append() [1/7]

void ByteBuffer::append ( const ByteBuffer buffer)
inline
462 {
463 if (buffer.wpos())
464 append(buffer.contents(), buffer.wpos());
465 }
void append(T value)
Definition: ByteBuffer.hpp:140
size_t wpos() const
Definition: ByteBuffer.hpp:324

References append(), contents(), and wpos().

+ Here is the call graph for this function:

◆ append() [2/7]

void ByteBuffer::append ( const char *  src,
size_t  size 
)
inline
410 {
411 append((const uint8_t *)src, size);
412 }

References append().

+ Here is the call graph for this function:

◆ append() [3/7]

template<class T >
void ByteBuffer::append ( const T *  src,
size_t  size 
)
inline
421 {
422 append((const uint8_t *) src, size);
423 }

References append().

+ Here is the call graph for this function:

◆ append() [4/7]

template<class T , class SubT >
void ByteBuffer::append ( const T *  t,
size_t  t_size,
const SubT *  sub_t,
int  count 
)
inline
427 {
428 append((const uint8_t *) t, t_size);
429 append((const uint8_t *) sub_t, sizeof(SubT) * count);
430 }
size_t count(GridTypeListContainer< SPECIFIC_TYPE > const &elements, SPECIFIC_TYPE *)
Definition: GridReferenceContainer.hpp:100

References append(), and GridTypeListIterator::count().

+ Here is the call graph for this function:

◆ append() [5/7]

void ByteBuffer::append ( const uint8_t *  src,
size_t  cnt 
)
inline
433 {
434 if (!cnt)
436
437 if (!src)
439
440 assert(maximum_length() < 10000000);
441
442 size_t const newSize = _wpos + cnt;
443 if (_storage.capacity() < newSize) // custom memory allocation rules
444 {
445 if (newSize < 100)
446 _storage.reserve(300);
447 else if (newSize < 750)
448 _storage.reserve(2500);
449 else if (newSize < 6000)
450 _storage.reserve(10000);
451 else
452 _storage.reserve(400000);
453 }
454
455 if (_storage.size() < newSize)
456 _storage.resize(newSize);
457 std::memcpy(&_storage[_wpos], src, cnt);
458 _wpos = newSize;
459 }
Definition: ByteBuffer.hpp:70
size_t maximum_length() const
Definition: ByteBuffer.hpp:332

References _storage, _wpos, and maximum_length().

+ Here is the call graph for this function:

◆ append() [6/7]

void ByteBuffer::append ( std::string  string)
inline
415 {
416 append(string.c_str(), string.size());
417 }

References append().

+ Here is the call graph for this function:

◆ append() [7/7]

template<typename T >
void ByteBuffer::append ( value)
inline
141 {
142 append((uint8_t *)&value, sizeof(value));
143 }

References append().

Referenced by append(), Horizon::Char::HC_ACK_CHARINFO_PER_PAGE::prepare(), Horizon::Char::HC_ACCEPT_ENTER::prepare(), Horizon::Auth::AuthSocket::read_handler(), Horizon::Char::CharSocket::read_handler(), Horizon::Zone::ZoneSocket::read_handler(), Horizon::Auth::AC_ACCEPT_LOGIN::serialize(), Horizon::Auth::AC_LOGIN_OTP::serialize(), Horizon::Auth::AC_REFUSE_LOGIN::serialize(), Horizon::Char::HC_ACCEPT_ENTER2::serialize(), Horizon::Char::HC_ACCEPT_MAKECHAR::serialize(), Horizon::Char::HC_NOTIFY_ZONESVR::serialize(), Horizon::Zone::ZC_ACCEPT_ENTER::serialize(), Horizon::Zone::ZC_ACCEPT_ENTER2::serialize(), Horizon::Zone::ZC_ACCEPT_ENTER3::serialize(), Horizon::Zone::ZC_ACK_ACCOUNTNAME::serialize(), Horizon::Zone::ZC_ACK_BAN_GUILD::serialize(), Horizon::Zone::ZC_ACK_BAN_GUILD_SSO::serialize(), Horizon::Zone::ZC_ACK_CHANGE_GUILD_POSITIONINFO::serialize(), Horizon::Zone::ZC_ACK_LEAVE_GUILD::serialize(), Horizon::Zone::ZC_ACK_RANKING::serialize(), Horizon::Zone::ZC_ACK_REQNAMEALL::serialize(), Horizon::Zone::ZC_ACK_REQNAMEALL2::serialize(), Horizon::Zone::ZC_ACK_REQ_JOIN_GROUP::serialize(), Horizon::Zone::ZC_ADD_MEMBER_TO_GROUP::serialize(), Horizon::Zone::ZC_BAN_LIST::serialize(), Horizon::Zone::ZC_CHANGE_CHATROOM::serialize(), Horizon::Zone::ZC_ENTER_ROOM::serialize(), Horizon::Zone::ZC_GROUP_LIST::serialize(), Horizon::Zone::ZC_GUILD_CHAT::serialize(), Horizon::Zone::ZC_GUILD_INFO::serialize(), Horizon::Zone::ZC_GUILD_INFO2::serialize(), Horizon::Zone::ZC_GUILD_NOTICE::serialize(), Horizon::Zone::ZC_GUILD_POSITION::serialize(), Horizon::Zone::ZC_GUILD_SKILLINFO::serialize(), Horizon::Zone::ZC_INVENTORY_START::serialize(), Horizon::Zone::ZC_MEMBERMGR_INFO::serialize(), Horizon::Zone::ZC_MENU_LIST::serialize(), Horizon::Zone::ZC_MYGUILD_BASIC_INFO::serialize(), Horizon::Zone::ZC_NOTIFY_ACT::serialize(), Horizon::Zone::ZC_NOTIFY_CHAT::serialize(), Horizon::Zone::ZC_NOTIFY_MOVE::serialize(), Horizon::Zone::ZC_NOTIFY_MOVEENTRY11::serialize(), Horizon::Zone::ZC_NOTIFY_NEWENTRY11::serialize(), Horizon::Zone::ZC_NOTIFY_PLAYERCHAT::serialize(), Horizon::Zone::ZC_NOTIFY_PLAYERMOVE::serialize(), Horizon::Zone::ZC_NOTIFY_STANDENTRY11::serialize(), Horizon::Zone::ZC_NPCACK_MAPMOVE::serialize(), Horizon::Zone::ZC_PARTY_JOIN_REQ::serialize(), Horizon::Zone::ZC_PARTY_JOIN_REQ_ACK::serialize(), Horizon::Zone::ZC_POSITION_ID_NAME_INFO::serialize(), Horizon::Zone::ZC_REQ_ADD_FRIENDS::serialize(), Horizon::Zone::ZC_REQ_ALLY_GUILD::serialize(), Horizon::Zone::ZC_REQ_JOIN_GROUP::serialize(), Horizon::Zone::ZC_REQ_JOIN_GUILD::serialize(), Horizon::Zone::ZC_ROLE_CHANGE::serialize(), Horizon::Zone::ZC_ROOM_NEWENTRY::serialize(), Horizon::Zone::ZC_SKILLINFO_LIST::serialize(), Horizon::Zone::ZC_STORE_ITEMLIST_EQUIP_V6::serialize(), Horizon::Zone::ZC_STORE_ITEMLIST_NORMAL_V5::serialize(), Horizon::Zone::ZC_UPDATE_GDID::serialize(), Horizon::Zone::ZC_WHISPER::serialize(), and Horizon::Auth::CA_LOGIN::serialize().

+ Here is the call graph for this function:

◆ clear()

void ByteBuffer::clear ( )
inline
129 {
130 _storage.clear();
131 reset();
132 }
void reset()
Definition: ByteBuffer.hpp:134

References _storage, and reset().

+ Here is the call graph for this function:

◆ contents() [1/2]

uint8_t * ByteBuffer::contents ( )
inline
307 {
308 if (_storage.empty())
309 throw ByteBufferException();
310 return _storage.data();
311 }
Definition: ByteBuffer.hpp:48

References _storage.

Referenced by append(), and ByteBuffer().

+ Here is the caller graph for this function:

◆ contents() [2/2]

uint8_t const * ByteBuffer::contents ( ) const
inline
314 {
315 if (_storage.empty())
316 throw ByteBufferException();
317 return _storage.data();
318 }

References _storage.

◆ emplace_size()

template<typename SizeT = uint16_t, typename std::enable_if< std::is_integral< SizeT >::value >::type * = nullptr>
void ByteBuffer::emplace_size ( std::size_t  pos = 2)
inline
486 {
487 _storage.emplace(_storage.begin() + pos, 0);
488 _storage.emplace(_storage.begin() + pos + 1, 0);
489 _wpos += 2;
490 put(pos, (uint8_t *) &_wpos, sizeof(SizeT));
491 }
void put(size_t pos, T value)
Definition: ByteBuffer.hpp:145

References _storage, _wpos, and put().

+ Here is the call graph for this function:

◆ ensure_free_space()

void ByteBuffer::ensure_free_space ( )
inline
351 {
352 // resize buffer if it's already full
353 if (remaining_space() == 0)
354 _storage.resize(_storage.size() * 3 / 2);
355 }
size_t remaining_space() const
Definition: ByteBuffer.hpp:334

References _storage, and remaining_space().

Referenced by Horizon::Networking::Socket< SocketType >::async_read(), and Horizon::Networking::Socket< SocketType >::async_read_with_callback().

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

◆ finish_reading()

void ByteBuffer::finish_reading ( )
inline
320{ _rpos = wpos(); }

References _rpos, and wpos().

+ Here is the call graph for this function:

◆ flush()

void ByteBuffer::flush ( )
inline
340 {
341 if (_rpos) {
342 if (_rpos != _wpos)
344 _wpos -= _rpos;
345 _rpos = 0;
346 }
347 }
uint8_t * get_base_pointer()
Definition: ByteBuffer.hpp:326
uint8_t * get_read_pointer()
Definition: ByteBuffer.hpp:327
size_t active_length() const
Definition: ByteBuffer.hpp:333

References _rpos, _wpos, active_length(), get_base_pointer(), and get_read_pointer().

Referenced by Horizon::Networking::Socket< SocketType >::async_read(), and Horizon::Networking::Socket< SocketType >::async_read_with_callback().

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

◆ get_base_pointer()

uint8_t * ByteBuffer::get_base_pointer ( )
inline
326{ return _storage.data(); }

References _storage.

Referenced by flush(), get_read_pointer(), and get_write_pointer().

+ Here is the caller graph for this function:

◆ get_read_pointer()

uint8_t * ByteBuffer::get_read_pointer ( )
inline

◆ get_write_pointer()

uint8_t * ByteBuffer::get_write_pointer ( )
inline
328{ return get_base_pointer() + _wpos; }

References _wpos, and get_base_pointer().

Referenced by Horizon::Networking::Socket< SocketType >::async_read(), Horizon::Networking::Socket< SocketType >::async_read_with_callback(), and to_string().

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

◆ hexlike()

void ByteBuffer::hexlike ( ) const
87{
88 uint32_t j = 1, k = 1;
89
90 std::ostringstream o;
91 o << "STORAGE_SIZE: " << active_length();
92
93 for (uint32_t i = 0; i < active_length(); ++i)
94 {
95 char buf[3];
96 snprintf(buf, 3, "%2X ", read<uint8_t>(i));
97 if ((i == (j * 8)) && ((i != (k * 16))))
98 {
99 o << "| ";
100 ++j;
101 }
102 else if (i == (k * 16))
103 {
104 o << "\n";
105 ++k;
106 ++j;
107 }
108
109 o << buf;
110 }
111 o << " ";
112
113 std::cout << o.str() << std::endl;
114
115 //TC_LOG_TRACE("network", "%s", o.str().c_str());
116}

References active_length().

+ Here is the call graph for this function:

◆ is_empty()

bool ByteBuffer::is_empty ( ) const
inline
336{ return _storage.empty(); }

References _storage.

Referenced by Horizon::Auth::AuthSession::transmit_buffer(), Horizon::Char::CharSession::transmit_buffer(), and Horizon::Zone::ZoneSession::transmit_buffer().

+ Here is the caller graph for this function:

◆ maximum_length()

size_t ByteBuffer::maximum_length ( ) const
inline
332{ return _storage.size(); }

References _storage.

Referenced by append(), operator[](), put(), read(), read_skip(), and reserve().

+ Here is the caller graph for this function:

◆ operator<<() [1/10]

ByteBuffer & ByteBuffer::operator<< ( double  value)
inline
208 {
209 append<double>(value);
210 return *this;
211 }

◆ operator<<() [2/10]

ByteBuffer & ByteBuffer::operator<< ( float  value)
inline
202 {
203 append<float>(value);
204 return *this;
205 }

◆ operator<<() [3/10]

ByteBuffer & ByteBuffer::operator<< ( int16_t  value)
inline
183 {
184 append<int16_t>(value);
185 return *this;
186 }

◆ operator<<() [4/10]

ByteBuffer & ByteBuffer::operator<< ( int32_t  value)
inline
189 {
190 append<int32_t>(value);
191 return *this;
192 }

◆ operator<<() [5/10]

ByteBuffer & ByteBuffer::operator<< ( int64_t  value)
inline
195 {
196 append<int64_t>(value);
197 return *this;
198 }

◆ operator<<() [6/10]

ByteBuffer & ByteBuffer::operator<< ( int8_t  value)
inline
177 {
178 append<int8_t>(value);
179 return *this;
180 }

◆ operator<<() [7/10]

ByteBuffer & ByteBuffer::operator<< ( uint16_t  value)
inline
158 {
159 append<uint16_t>(value);
160 return *this;
161 }

◆ operator<<() [8/10]

ByteBuffer & ByteBuffer::operator<< ( uint32_t  value)
inline
164 {
165 append<uint32_t>(value);
166 return *this;
167 }

◆ operator<<() [9/10]

ByteBuffer & ByteBuffer::operator<< ( uint64_t  value)
inline
170 {
171 append<uint64_t>(value);
172 return *this;
173 }

◆ operator<<() [10/10]

ByteBuffer & ByteBuffer::operator<< ( uint8_t  value)
inline
152 {
153 append<uint8_t>(value);
154 return *this;
155 }

◆ operator=()

ByteBuffer & ByteBuffer::operator= ( ByteBuffer const &  right)
inline
114 {
115 if (this != &right)
116 {
117 _rpos = right._rpos;
118 _wpos = right._wpos;
119 _storage = right._storage;
120 }
121
122 return *this;
123 }

References _rpos, _storage, and _wpos.

◆ operator>>() [1/11]

ByteBuffer & ByteBuffer::operator>> ( bool &  value)
inline
214 {
215 value = read<char>() > 0 ? true : false;
216 return *this;
217 }

◆ operator>>() [2/11]

ByteBuffer & ByteBuffer::operator>> ( double &  value)
inline
277 {
278 value = read<double>();
279 if (!std::isfinite(value))
280 throw ByteBufferException();
281 return *this;
282 }

◆ operator>>() [3/11]

ByteBuffer & ByteBuffer::operator>> ( float &  value)
inline
269 {
270 value = read<float>();
271 if (!std::isfinite(value))
272 throw ByteBufferException();
273 return *this;
274 }

◆ operator>>() [4/11]

ByteBuffer & ByteBuffer::operator>> ( int16_t &  value)
inline
251 {
252 value = read<short>();
253 return *this;
254 }

◆ operator>>() [5/11]

ByteBuffer & ByteBuffer::operator>> ( int32_t &  value)
inline
257 {
258 value = read<int>();
259 return *this;
260 }

◆ operator>>() [6/11]

ByteBuffer & ByteBuffer::operator>> ( int64_t &  value)
inline
263 {
264 value = read<long>();
265 return *this;
266 }

◆ operator>>() [7/11]

ByteBuffer & ByteBuffer::operator>> ( int8_t &  value)
inline
245 {
246 value = static_cast<int>(read<signed char>());
247 return *this;
248 }

◆ operator>>() [8/11]

ByteBuffer & ByteBuffer::operator>> ( uint16_t &  value)
inline
226 {
227 value = read<unsigned short>();
228 return *this;
229 }

◆ operator>>() [9/11]

ByteBuffer & ByteBuffer::operator>> ( uint32_t &  value)
inline
232 {
233 value = read<unsigned int>();
234 return *this;
235 }

◆ operator>>() [10/11]

ByteBuffer & ByteBuffer::operator>> ( uint64_t &  value)
inline
238 {
239 value = read<unsigned long>();
240 return *this;
241 }

◆ operator>>() [11/11]

ByteBuffer & ByteBuffer::operator>> ( uint8_t &  value)
inline
220 {
221 value = static_cast<int>(read<unsigned char>());
222 return *this;
223 }

◆ operator[]() [1/2]

uint8_t & ByteBuffer::operator[] ( size_t const  pos)
inline
285 {
286 if (pos >= maximum_length())
287 throw ByteBufferPositionException(false, pos, 1, maximum_length());
288 return _storage[pos];
289 }
Definition: ByteBuffer.hpp:62

References _storage, and maximum_length().

+ Here is the call graph for this function:

◆ operator[]() [2/2]

uint8_t const & ByteBuffer::operator[] ( size_t const  pos) const
inline
292 {
293 if (pos >= maximum_length())
294 throw ByteBufferPositionException(false, pos, 1, maximum_length());
295 return _storage[pos];
296 }

References _storage, and maximum_length().

+ Here is the call graph for this function:

◆ print_storage()

void ByteBuffer::print_storage ( ) const
60{
61 std::ostringstream o;
62 o << "STORAGE_SIZE: " << _storage.size();
63 for (uint32_t i = 0; i < _storage.size(); ++i)
64 o << read<uint8_t>(i) << " - ";
65 o << " ";
66
67 std::cout << o.str() << std::endl;
68 //TC_LOG_TRACE("network", "%s", o.str().c_str());
69}

References _storage.

◆ put() [1/2]

void ByteBuffer::put ( size_t  pos,
const uint8_t *  src,
size_t  cnt 
)
inline
468 {
469 if (pos + cnt > maximum_length())
470 throw ByteBufferPositionException(true, pos, cnt, maximum_length());
471
472 if (!src)
474
475 std::memcpy(&_storage[pos], src, cnt);
476 }

References _storage, _wpos, and maximum_length().

+ Here is the call graph for this function:

◆ put() [2/2]

template<typename T >
void ByteBuffer::put ( size_t  pos,
value 
)
inline
146 {
147 static_assert(std::is_fundamental<T>::value, "append(compound)");
148 put(pos, (uint8_t *)&value, sizeof(value));
149 }

References put().

Referenced by emplace_size(), and put().

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

◆ read() [1/4]

template<typename T >
T ByteBuffer::read ( )
inline
380 {
381 T r = read<T>(_rpos);
382 _rpos += sizeof(T);
383 return r;
384 }

References _rpos.

Referenced by Horizon::Auth::CA_LOGIN::deserialize(), Horizon::Char::CH_DELETE_CHAR::deserialize(), Horizon::Char::CH_DELETE_CHAR2::deserialize(), Horizon::Char::CH_DELETE_CHAR3::deserialize(), Horizon::Char::CH_EDIT_SECOND_PASSWD::deserialize(), Horizon::Char::CH_MAKE_CHAR::deserialize(), Horizon::Char::CH_MAKE_SECOND_PASSWD::deserialize(), Horizon::Char::CH_SECOND_PASSWD_ACK::deserialize(), Horizon::Zone::CZ_ACK_STORE_PASSWORD::deserialize(), Horizon::Zone::CZ_ADD_FRIENDS::deserialize(), Horizon::Zone::CZ_AUCTION_ITEM_SEARCH::deserialize(), Horizon::Zone::CZ_BATTLEFIELD_CHAT::deserialize(), Horizon::Zone::CZ_BROADCAST::deserialize(), Horizon::Zone::CZ_CHANGE_CHATROOM::deserialize(), Horizon::Zone::CZ_CHECK_RECEIVE_CHARACTER_NAME::deserialize(), Horizon::Zone::CZ_CLAN_CHAT::deserialize(), Horizon::Zone::CZ_CREATE_CHATROOM::deserialize(), Horizon::Zone::CZ_GUILD_CHAT::deserialize(), Horizon::Zone::CZ_GUILD_NOTICE::deserialize(), Horizon::Zone::CZ_INPUT_EDITDLGSTR::deserialize(), Horizon::Zone::CZ_ITEM_CREATE::deserialize(), Horizon::Zone::CZ_ITEM_CREATE_EX::deserialize(), Horizon::Zone::CZ_LOCALBROADCAST::deserialize(), Horizon::Zone::CZ_MAIL_SEND::deserialize(), Horizon::Zone::CZ_MAKE_GROUP::deserialize(), Horizon::Zone::CZ_MAKE_GROUP2::deserialize(), Horizon::Zone::CZ_MOVETO_MAP::deserialize(), Horizon::Zone::CZ_PARTY_JOIN_REQ::deserialize(), Horizon::Zone::CZ_PRIVATE_AIRSHIP_REQUEST::deserialize(), Horizon::Zone::CZ_RECALL::deserialize(), Horizon::Zone::CZ_RECALL_GID::deserialize(), Horizon::Zone::CZ_REGISTER_GUILD_EMBLEM_IMG::deserialize(), Horizon::Zone::CZ_REG_CHANGE_GUILD_POSITIONINFO::deserialize(), Horizon::Zone::CZ_RENAME_MER::deserialize(), Horizon::Zone::CZ_RENAME_PET::deserialize(), Horizon::Zone::CZ_REQUEST_CHAT::deserialize(), Horizon::Zone::CZ_REQUEST_CHAT_PARTY::deserialize(), Horizon::Zone::CZ_REQUEST_MOVE::deserialize(), Horizon::Zone::CZ_REQUEST_MOVE2::deserialize(), Horizon::Zone::CZ_REQUEST_MOVENPC::deserialize(), Horizon::Zone::CZ_REQ_BAN_GUILD::deserialize(), Horizon::Zone::CZ_REQ_DISORGANIZE_GUILD::deserialize(), Horizon::Zone::CZ_REQ_ENTER_ROOM::deserialize(), Horizon::Zone::CZ_REQ_EXPEL_GROUP_MEMBER::deserialize(), Horizon::Zone::CZ_REQ_EXPEL_MEMBER::deserialize(), Horizon::Zone::CZ_REQ_GIVE_MANNER_BYNAME::deserialize(), Horizon::Zone::CZ_REQ_JOIN_GUILD2::deserialize(), Horizon::Zone::CZ_REQ_LEAVE_GUILD::deserialize(), Horizon::Zone::CZ_REQ_MAIL_RETURN::deserialize(), Horizon::Zone::CZ_REQ_MAKE_GUILD::deserialize(), Horizon::Zone::CZ_REQ_OPENSTORE::deserialize(), Horizon::Zone::CZ_REQ_OPENSTORE2::deserialize(), Horizon::Zone::CZ_REQ_OPEN_BUYING_STORE::deserialize(), Horizon::Zone::CZ_REQ_ROLE_CHANGE::deserialize(), Horizon::Zone::CZ_REQ_STATUS_GM::deserialize(), Horizon::Zone::CZ_USE_SKILL_TOGROUND_WITHTALKBOX::deserialize(), Horizon::Zone::CZ_USE_SKILL_TOGROUND_WITHTALKBOX2::deserialize(), and Horizon::Zone::CZ_WHISPER::deserialize().

◆ read() [2/4]

void ByteBuffer::read ( ByteBuffer buf,
size_t  len 
)
inline
403 {
404 std::memcpy(&buf._storage[buf._wpos], &_storage[_rpos], len);
405 buf._wpos += len;
406 _rpos += len;
407 }

References _rpos, _storage, and _wpos.

◆ read() [3/4]

void ByteBuffer::read ( char *  dest,
size_t  len 
)
inline
395 {
396 if (_rpos + len > maximum_length())
398 std::memcpy((void *) dest, &_storage[_rpos], len);
399 _rpos += len;
400 }

References _rpos, _storage, and maximum_length().

+ Here is the call graph for this function:

◆ read() [4/4]

template<typename T >
T ByteBuffer::read ( size_t  pos) const
inline
387 {
388 if (pos + sizeof(T) > maximum_length())
389 throw ByteBufferPositionException(false, pos, sizeof(T), maximum_length());
390 T val = *(reinterpret_cast<T const*>(& _storage[pos]));
391 return val;
392 }

References _storage, and maximum_length().

+ Here is the call graph for this function:

◆ read_completed()

void ByteBuffer::read_completed ( size_t  bytes)
inline
321{ _rpos += bytes; }

References _rpos.

Referenced by Horizon::Auth::AuthSocket::read_handler(), Horizon::Char::CharSocket::read_handler(), and Horizon::Zone::ZoneSocket::read_handler().

+ Here is the caller graph for this function:

◆ read_skip() [1/3]

template<typename T >
void ByteBuffer::read_skip ( )
inline
369{ read_skip(sizeof(T)); }
void read_skip()
Definition: ByteBuffer.hpp:369

References read_skip().

Referenced by read_skip().

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

◆ read_skip() [2/3]

template<>
void ByteBuffer::read_skip ( )
inline
500{
501 read_skip<char*>();
502}

◆ read_skip() [3/3]

void ByteBuffer::read_skip ( size_t  skip)
inline
372 {
373 if (_rpos + skip > maximum_length())
374 throw ByteBufferPositionException(false, _rpos, skip, maximum_length());
375 _rpos += skip;
376 }

References _rpos, and maximum_length().

+ Here is the call graph for this function:

◆ remaining_space()

size_t ByteBuffer::remaining_space ( ) const
inline
334{ return _storage.size() - _wpos; }

References _storage, and _wpos.

Referenced by Horizon::Networking::Socket< SocketType >::async_read(), Horizon::Networking::Socket< SocketType >::async_read_with_callback(), and ensure_free_space().

+ Here is the caller graph for this function:

◆ reserve()

void ByteBuffer::reserve ( size_t  ressize)
inline
363 {
364 if (ressize > maximum_length())
365 _storage.reserve(ressize);
366 }

References _storage, and maximum_length().

Referenced by ByteBuffer().

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

◆ reset()

void ByteBuffer::reset ( )
inline
135 {
136 _wpos = 0;
137 _rpos = 0;
138 }

References _rpos, and _wpos.

Referenced by clear().

+ Here is the caller graph for this function:

◆ resize()

void ByteBuffer::resize ( size_t  new_size)
inline
358 {
359 _storage.resize(new_size);
360 }

References _storage.

Referenced by Horizon::Networking::Socket< SocketType >::Socket().

+ Here is the caller graph for this function:

◆ rpos() [1/2]

size_t ByteBuffer::rpos ( ) const
inline
298{ return _rpos; }

References _rpos.

◆ rpos() [2/2]

size_t ByteBuffer::rpos ( size_t  rpos_)
inline
301 {
302 _rpos = rpos_;
303 return _rpos;
304 }

References _rpos.

◆ textlike()

void ByteBuffer::textlike ( ) const
72{
73 std::ostringstream o;
74 o << "STORAGE_SIZE: " << active_length();
75 for (uint32_t i = 0; i < active_length(); ++i)
76 {
77 char buf[2];
78 snprintf(buf, 2, "%c", read<uint8_t>(i));
79 o << buf;
80 }
81 o << " ";
82 std::cout << o.str() << std::endl;
83 //TC_LOG_TRACE("network", "%s", o.str().c_str());
84}

References active_length().

+ Here is the call graph for this function:

◆ to_string()

std::string ByteBuffer::to_string ( )
inline
330{ return std::string(get_read_pointer(), get_write_pointer()); }
uint8_t * get_write_pointer()
Definition: ByteBuffer.hpp:328

References get_read_pointer(), and get_write_pointer().

Referenced by Horizon::Char::CharSocket::read_handler(), and Horizon::Auth::AC_ACCEPT_LOGIN::serialize().

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

◆ wpos()

size_t ByteBuffer::wpos ( ) const
inline
324{ return _wpos; }

References _wpos.

Referenced by append(), and finish_reading().

+ Here is the caller graph for this function:

◆ write_completed()

void ByteBuffer::write_completed ( size_t  bytes)
inline
322{ _wpos += bytes; }

References _wpos.

Referenced by Horizon::Networking::Socket< SocketType >::read_handler_internal().

+ Here is the caller graph for this function:

Member Data Documentation

◆ _rpos

◆ _storage

◆ _wpos

◆ DEFAULT_SIZE

const size_t ByteBuffer::DEFAULT_SIZE = 0x1000
static

Referenced by ByteBuffer().


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