TrinityCore
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Modules Pages
ByteBuffer.h
Go to the documentation of this file.
1 /*
2  * Copyright (C) 2008-2016 TrinityCore <http://www.trinitycore.org/>
3  * Copyright (C) 2005-2009 MaNGOS <http://getmangos.com/>
4  *
5  * This program is free software; you can redistribute it and/or modify it
6  * under the terms of the GNU General Public License as published by the
7  * Free Software Foundation; either version 2 of the License, or (at your
8  * option) any later version.
9  *
10  * This program is distributed in the hope that it will be useful, but WITHOUT
11  * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
12  * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
13  * more details.
14  *
15  * You should have received a copy of the GNU General Public License along
16  * with this program. If not, see <http://www.gnu.org/licenses/>.
17  */
18 
19 #ifndef _BYTEBUFFER_H
20 #define _BYTEBUFFER_H
21 
22 #include "Define.h"
23 #include "Errors.h"
24 #include "ByteConverter.h"
25 #include "Util.h"
26 
27 #include <exception>
28 #include <list>
29 #include <map>
30 #include <string>
31 #include <vector>
32 #include <cstring>
33 #include <time.h>
34 #include <cmath>
35 #include <type_traits>
36 
37 class MessageBuffer;
38 
39 // Root of ByteBuffer exception hierarchy
40 class TC_SHARED_API ByteBufferException : public std::exception
41 {
42 public:
43  ~ByteBufferException() throw() { }
44 
45  char const* what() const throw() override { return msg_.c_str(); }
46 
47 protected:
48  std::string & message() throw() { return msg_; }
49 
50 private:
51  std::string msg_;
52 };
53 
55 {
56 public:
57  ByteBufferPositionException(bool add, size_t pos, size_t size, size_t valueSize);
58 
60 };
61 
63 {
64 public:
65  ByteBufferSourceException(size_t pos, size_t size, size_t valueSize);
66 
68 };
69 
71 {
72  public:
73  static size_t const DEFAULT_SIZE = 0x1000;
74  static uint8 const InitialBitPos = 8;
75 
76  // constructor
77  ByteBuffer() : _rpos(0), _wpos(0), _bitpos(InitialBitPos), _curbitval(0)
78  {
79  _storage.reserve(DEFAULT_SIZE);
80  }
81 
82  ByteBuffer(size_t reserve) : _rpos(0), _wpos(0), _bitpos(InitialBitPos), _curbitval(0)
83  {
84  _storage.reserve(reserve);
85  }
86 
87  ByteBuffer(ByteBuffer&& buf) : _rpos(buf._rpos), _wpos(buf._wpos),
88  _bitpos(buf._bitpos), _curbitval(buf._curbitval), _storage(buf.Move()) { }
89 
90  ByteBuffer(ByteBuffer const& right) : _rpos(right._rpos), _wpos(right._wpos),
91  _bitpos(right._bitpos), _curbitval(right._curbitval), _storage(right._storage) { }
92 
93  ByteBuffer(MessageBuffer&& buffer);
94 
95  std::vector<uint8>&& Move()
96  {
97  _rpos = 0;
98  _wpos = 0;
99  _bitpos = InitialBitPos;
100  _curbitval = 0;
101  return std::move(_storage);
102  }
103 
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  }
117 
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  }
131 
132  virtual ~ByteBuffer() { }
133 
134  void clear()
135  {
136  _rpos = 0;
137  _wpos = 0;
138  _bitpos = InitialBitPos;
139  _curbitval = 0;
140  _storage.clear();
141  }
142 
143  template <typename T> void append(T value)
144  {
145  static_assert(std::is_fundamental<T>::value, "append(compound)");
146  EndianConvert(value);
147  append((uint8 *)&value, sizeof(value));
148  }
149 
150  void FlushBits()
151  {
152  if (_bitpos == 8)
153  return;
154 
155  _bitpos = 8;
156 
157  append((uint8 *)&_curbitval, sizeof(uint8));
158  _curbitval = 0;
159  }
160 
161  void ResetBitPos()
162  {
163  if (_bitpos > 7)
164  return;
165 
166  _bitpos = 8;
167  _curbitval = 0;
168  }
169 
170  bool WriteBit(uint32 bit)
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  }
185 
186  bool ReadBit()
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  }
197 
198  template <typename T> void WriteBits(T value, int32 bits)
199  {
200  for (int32 i = bits - 1; i >= 0; --i)
201  WriteBit((value >> i) & 1);
202  }
203 
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  }
213 
214  // Reads a byte (if needed) in-place
216  {
217  if (b != 0)
218  b ^= read<uint8>();
219  }
220 
222  {
223  if (b != 0)
224  append<uint8>(b ^ 1);
225  }
226 
227  template <typename T> void put(size_t pos, T value)
228  {
229  static_assert(std::is_fundamental<T>::value, "append(compound)");
230  EndianConvert(value);
231  put(pos, (uint8 *)&value, sizeof(value));
232  }
233 
246  template <typename T> void PutBits(size_t pos, T value, uint32 bitCount)
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  }
264 
266  {
267  append<uint8>(value);
268  return *this;
269  }
270 
272  {
273  append<uint16>(value);
274  return *this;
275  }
276 
278  {
279  append<uint32>(value);
280  return *this;
281  }
282 
284  {
285  append<uint64>(value);
286  return *this;
287  }
288 
289  // signed as in 2e complement
291  {
292  append<int8>(value);
293  return *this;
294  }
295 
297  {
298  append<int16>(value);
299  return *this;
300  }
301 
303  {
304  append<int32>(value);
305  return *this;
306  }
307 
309  {
310  append<int64>(value);
311  return *this;
312  }
313 
314  // floating points
316  {
317  append<float>(value);
318  return *this;
319  }
320 
322  {
323  append<double>(value);
324  return *this;
325  }
326 
327  ByteBuffer &operator<<(const std::string &value)
328  {
329  if (size_t len = value.length())
330  append((uint8 const*)value.c_str(), len);
331  append<uint8>(0);
332  return *this;
333  }
334 
335  ByteBuffer &operator<<(const char *str)
336  {
337  if (size_t len = (str ? strlen(str) : 0))
338  append((uint8 const*)str, len);
339  append<uint8>(0);
340  return *this;
341  }
342 
344  {
345  value = read<char>() > 0 ? true : false;
346  return *this;
347  }
348 
350  {
351  value = read<uint8>();
352  return *this;
353  }
354 
356  {
357  value = read<uint16>();
358  return *this;
359  }
360 
362  {
363  value = read<uint32>();
364  return *this;
365  }
366 
368  {
369  value = read<uint64>();
370  return *this;
371  }
372 
373  //signed as in 2e complement
375  {
376  value = read<int8>();
377  return *this;
378  }
379 
381  {
382  value = read<int16>();
383  return *this;
384  }
385 
387  {
388  value = read<int32>();
389  return *this;
390  }
391 
393  {
394  value = read<int64>();
395  return *this;
396  }
397 
399  {
400  value = read<float>();
401  if (!std::isfinite(value))
402  throw ByteBufferException();
403  return *this;
404  }
405 
407  {
408  value = read<double>();
409  if (!std::isfinite(value))
410  throw ByteBufferException();
411  return *this;
412  }
413 
414  ByteBuffer &operator>>(std::string& value)
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  }
426 
427  uint8& operator[](size_t const pos)
428  {
429  if (pos >= size())
430  throw ByteBufferPositionException(false, pos, 1, size());
431  return _storage[pos];
432  }
433 
434  uint8 const& operator[](size_t const pos) const
435  {
436  if (pos >= size())
437  throw ByteBufferPositionException(false, pos, 1, size());
438  return _storage[pos];
439  }
440 
441  size_t rpos() const { return _rpos; }
442 
443  size_t rpos(size_t rpos_)
444  {
445  _rpos = rpos_;
446  return _rpos;
447  }
448 
449  void rfinish()
450  {
451  _rpos = wpos();
452  }
453 
454  size_t wpos() const { return _wpos; }
455 
456  size_t wpos(size_t wpos_)
457  {
458  _wpos = wpos_;
459  return _wpos;
460  }
461 
463  size_t bitwpos() const { return _wpos * 8 + 8 - _bitpos; }
464 
465  size_t bitwpos(size_t newPos)
466  {
467  _wpos = newPos / 8;
468  _bitpos = 8 - (newPos % 8);
469  return _wpos * 8 + 8 - _bitpos;
470  }
471 
472  template<typename T>
473  void read_skip() { read_skip(sizeof(T)); }
474 
475  void read_skip(size_t skip)
476  {
477  if (_rpos + skip > size())
478  throw ByteBufferPositionException(false, _rpos, skip, size());
479 
480  ResetBitPos();
481  _rpos += skip;
482  }
483 
484  template <typename T> T read()
485  {
486  ResetBitPos();
487  T r = read<T>(_rpos);
488  _rpos += sizeof(T);
489  return r;
490  }
491 
492  template <typename T> T read(size_t pos) const
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  }
500 
501  void read(uint8 *dest, size_t len)
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  }
510 
512  {
513  guid = 0;
514  ReadPackedUInt64(read<uint8>(), guid);
515  }
516 
518  {
519  for (uint32 i = 0; i < 8; ++i)
520  if (mask & (uint8(1) << i))
521  value |= (uint64(read<uint8>()) << (i * 8));
522  }
523 
524  std::string ReadString(uint32 length)
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  }
537 
540  void WriteString(std::string const& str)
541  {
542  if (size_t len = str.length())
543  append(str.c_str(), len);
544  }
545 
546  void WriteString(char const* str, size_t len)
547  {
548  if (len)
549  append(str, len);
550  }
551 
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  }
566 
568  {
569  time = ReadPackedTime();
570  return *this;
571  }
572 
574  {
575  if (_storage.empty())
576  throw ByteBufferException();
577  return _storage.data();
578  }
579 
580  uint8 const* contents() const
581  {
582  if (_storage.empty())
583  throw ByteBufferException();
584  return _storage.data();
585  }
586 
587  size_t size() const { return _storage.size(); }
588  bool empty() const { return _storage.empty(); }
589 
590  void resize(size_t newsize)
591  {
592  _storage.resize(newsize, 0);
593  _rpos = 0;
594  _wpos = size();
595  }
596 
597  void reserve(size_t ressize)
598  {
599  if (ressize > size())
600  _storage.reserve(ressize);
601  }
602 
603  void append(const char *src, size_t cnt)
604  {
605  return append((const uint8 *)src, cnt);
606  }
607 
608  template<class T> void append(const T *src, size_t cnt)
609  {
610  return append((const uint8 *)src, cnt * sizeof(T));
611  }
612 
613  void append(const uint8 *src, size_t cnt)
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  }
630 
631  void append(const ByteBuffer& buffer)
632  {
633  if (buffer.wpos())
634  append(buffer.contents(), buffer.wpos());
635  }
636 
637  // can be used in SMSG_MONSTER_MOVE opcode
638  void appendPackXYZ(float x, float y, float z)
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  }
646 
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  }
659 
660  static size_t PackUInt64(uint64 value, uint8* mask, uint8* result)
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  }
679 
680  void AppendPackedTime(time_t time)
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  }
686 
687  void put(size_t pos, const uint8 *src, size_t cnt)
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  }
697 
698  void print_storage() const;
699 
700  void textlike() const;
701 
702  void hexlike() const;
703 
704  protected:
705  size_t _rpos, _wpos, _bitpos;
707  std::vector<uint8> _storage;
708 };
709 
710 template <typename T>
711 inline ByteBuffer &operator<<(ByteBuffer &b, std::vector<T> v)
712 {
713  b << (uint32)v.size();
714  for (typename std::vector<T>::iterator i = v.begin(); i != v.end(); ++i)
715  {
716  b << *i;
717  }
718  return b;
719 }
720 
721 template <typename T>
722 inline ByteBuffer &operator>>(ByteBuffer &b, std::vector<T> &v)
723 {
724  uint32 vsize;
725  b >> vsize;
726  v.clear();
727  while (vsize--)
728  {
729  T t;
730  b >> t;
731  v.push_back(t);
732  }
733  return b;
734 }
735 
736 template <typename T>
737 inline ByteBuffer &operator<<(ByteBuffer &b, std::list<T> v)
738 {
739  b << (uint32)v.size();
740  for (typename std::list<T>::iterator i = v.begin(); i != v.end(); ++i)
741  {
742  b << *i;
743  }
744  return b;
745 }
746 
747 template <typename T>
748 inline ByteBuffer &operator>>(ByteBuffer &b, std::list<T> &v)
749 {
750  uint32 vsize;
751  b >> vsize;
752  v.clear();
753  while (vsize--)
754  {
755  T t;
756  b >> t;
757  v.push_back(t);
758  }
759  return b;
760 }
761 
762 template <typename K, typename V>
763 inline ByteBuffer &operator<<(ByteBuffer &b, std::map<K, V> &m)
764 {
765  b << (uint32)m.size();
766  for (typename std::map<K, V>::iterator i = m.begin(); i != m.end(); ++i)
767  {
768  b << i->first << i->second;
769  }
770  return b;
771 }
772 
773 template <typename K, typename V>
774 inline ByteBuffer &operator>>(ByteBuffer &b, std::map<K, V> &m)
775 {
776  uint32 msize;
777  b >> msize;
778  m.clear();
779  while (msize--)
780  {
781  K k;
782  V v;
783  b >> k >> v;
784  m.insert(make_pair(k, v));
785  }
786  return b;
787 }
788 
790 template<> inline std::string ByteBuffer::read<std::string>()
791 {
792  std::string tmp;
793  *this >> tmp;
794  return tmp;
795 }
796 
797 template<>
798 inline void ByteBuffer::read_skip<char*>()
799 {
800  std::string temp;
801  *this >> temp;
802 }
803 
804 template<>
805 inline void ByteBuffer::read_skip<char const*>()
806 {
807  read_skip<char*>();
808 }
809 
810 template<>
811 inline void ByteBuffer::read_skip<std::string>()
812 {
813  read_skip<char*>();
814 }
815 
816 #endif
ByteBuffer & operator<<(int32 value)
Definition: ByteBuffer.h:302
ByteBuffer & operator<<(int64 value)
Definition: ByteBuffer.h:308
ByteBuffer & operator=(ByteBuffer const &right)
Definition: ByteBuffer.h:104
uint8 * contents()
Definition: ByteBuffer.h:573
void read_skip()
Definition: ByteBuffer.h:473
Definition: ByteBuffer.h:70
int8_t int8
Definition: Define.h:148
ByteBuffer & operator<<(uint32 value)
Definition: ByteBuffer.h:277
ByteBuffer & operator>>(uint64 &value)
Definition: ByteBuffer.h:367
void append(const T *src, size_t cnt)
Definition: ByteBuffer.h:608
int64_t int64
Definition: Define.h:145
void ReadPackedUInt64(uint64 &guid)
Definition: ByteBuffer.h:511
ByteBuffer & operator>>(uint32 &value)
Definition: ByteBuffer.h:361
void read_skip(size_t skip)
Definition: ByteBuffer.h:475
ByteBuffer & operator<<(const char *str)
Definition: ByteBuffer.h:335
Definition: ByteBuffer.h:62
uint32 ReadBits(int32 bits)
Definition: ByteBuffer.h:204
void resize(size_t newsize)
Definition: ByteBuffer.h:590
void EndianConvert(T &val)
Definition: ByteConverter.h:48
std::string & message()
Definition: ByteBuffer.h:48
char const * what() const override
Definition: ByteBuffer.h:45
size_t wpos(size_t wpos_)
Definition: ByteBuffer.h:456
void ResetBitPos()
Definition: ByteBuffer.h:161
ByteBuffer(ByteBuffer const &right)
Definition: ByteBuffer.h:90
ByteBuffer & operator>>(int32 &value)
Definition: ByteBuffer.h:386
ByteBuffer & operator<<(int16 value)
Definition: ByteBuffer.h:296
ByteBuffer & operator<<(float value)
Definition: ByteBuffer.h:315
void FlushBits()
Definition: ByteBuffer.h:150
uint64_t uint64
Definition: g3dmath.h:170
ByteBuffer()
Definition: ByteBuffer.h:77
ByteBuffer & operator>>(int16 &value)
Definition: ByteBuffer.h:380
size_t bitwpos() const
Returns position of last written bit.
Definition: ByteBuffer.h:463
uint8 _curbitval
Definition: ByteBuffer.h:706
std::vector< uint8 > _storage
Definition: ByteBuffer.h:707
bool WriteBit(uint32 bit)
Definition: ByteBuffer.h:170
ByteBuffer(size_t reserve)
Definition: ByteBuffer.h:82
void appendPackXYZ(float x, float y, float z)
Definition: ByteBuffer.h:638
uint8 const & operator[](size_t const pos) const
Definition: ByteBuffer.h:434
void put(size_t pos, const uint8 *src, size_t cnt)
Definition: ByteBuffer.h:687
Definition: ByteBuffer.h:54
uint32 ReadPackedTime()
Definition: ByteBuffer.h:552
ByteBuffer & operator>>(ByteBuffer &b, std::vector< T > &v)
Definition: ByteBuffer.h:722
void ReadPackedUInt64(uint8 mask, uint64 &value)
Definition: ByteBuffer.h:517
ByteBuffer & operator=(ByteBuffer &&right)
Definition: ByteBuffer.h:118
std::string msg_
Definition: ByteBuffer.h:51
size_t wpos() const
Definition: ByteBuffer.h:454
void read(uint8 *dest, size_t len)
Definition: ByteBuffer.h:501
void PutBits(size_t pos, T value, uint32 bitCount)
Definition: ByteBuffer.h:246
ByteBuffer & operator>>(std::string &value)
Definition: ByteBuffer.h:414
static size_t PackUInt64(uint64 value, uint8 *mask, uint8 *result)
Definition: ByteBuffer.h:660
std::string ReadString(uint32 length)
Definition: ByteBuffer.h:524
void WriteString(std::string const &str)
Definition: ByteBuffer.h:540
ByteBuffer & operator>>(float &value)
Definition: ByteBuffer.h:398
ByteBuffer & ReadPackedTime(uint32 &time)
Definition: ByteBuffer.h:567
bool empty() const
Definition: ByteBuffer.h:588
size_t size() const
Definition: ByteBuffer.h:587
void AppendPackedUInt64(uint64 guid)
Definition: ByteBuffer.h:647
G3D::int16 z
Definition: Vector3int16.h:46
void put(size_t pos, T value)
Definition: ByteBuffer.h:227
int32_t int32
Definition: Define.h:146
uint32_t uint32
Definition: Define.h:150
uint64_t uint64
Definition: Define.h:149
ByteBuffer & operator<<(uint64 value)
Definition: ByteBuffer.h:283
G3D::int16 y
Definition: Vector2int16.h:38
#define TC_SHARED_API
Definition: Define.h:128
uint16_t uint16
Definition: Define.h:151
~ByteBufferPositionException()
Definition: ByteBuffer.h:59
uint16 bits() const
Returns the underlying bits in this representation. Equivalent to:
Definition: unorm16.h:89
void rfinish()
Definition: ByteBuffer.h:449
void AppendPackedTime(time_t time)
Definition: ByteBuffer.h:680
ByteBuffer & operator>>(uint8 &value)
Definition: ByteBuffer.h:349
uint8 const * contents() const
Definition: ByteBuffer.h:580
void WriteByteSeq(uint8 b)
Definition: ByteBuffer.h:221
void reserve(size_t ressize)
Definition: ByteBuffer.h:597
ByteBuffer(ByteBuffer &&buf)
Definition: ByteBuffer.h:87
float length(float v)
Definition: vectorMath.h:208
void append(T value)
Definition: ByteBuffer.h:143
TC_COMMON_API struct tm * localtime_r(const time_t *time, struct tm *result)
uint8_t uint8
Definition: g3dmath.h:164
T read(size_t pos) const
Definition: ByteBuffer.h:492
ByteBuffer & operator>>(bool &value)
Definition: ByteBuffer.h:343
size_t bitwpos(size_t newPos)
Definition: ByteBuffer.h:465
uint8 & operator[](size_t const pos)
Definition: ByteBuffer.h:427
std::vector< uint8 > && Move()
Definition: ByteBuffer.h:95
size_t _bitpos
Definition: ByteBuffer.h:705
~ByteBufferException()
Definition: ByteBuffer.h:43
void WriteString(char const *str, size_t len)
Definition: ByteBuffer.h:546
Definition: ByteBuffer.h:40
ByteBuffer & operator<<(double value)
Definition: ByteBuffer.h:321
uint8_t uint8
Definition: Define.h:152
void ReadByteSeq(uint8 &b)
Definition: ByteBuffer.h:215
#define ASSERT
Definition: Errors.h:55
void append(const uint8 *src, size_t cnt)
Definition: ByteBuffer.h:613
virtual ~ByteBuffer()
Definition: ByteBuffer.h:132
ByteBuffer & operator>>(int8 &value)
Definition: ByteBuffer.h:374
const FieldDescriptor value
Definition: descriptor.h:1522
int16_t int16
Definition: Define.h:147
uint32_t uint32
Definition: g3dmath.h:168
G3D::int16 x
Definition: Vector2int16.h:37
ByteBuffer & operator<<(uint8 value)
Definition: ByteBuffer.h:265
size_t rpos() const
Definition: ByteBuffer.h:441
ByteBuffer & operator<<(uint16 value)
Definition: ByteBuffer.h:271
~ByteBufferSourceException()
Definition: ByteBuffer.h:67
ByteBuffer & operator>>(uint16 &value)
Definition: ByteBuffer.h:355
ByteBuffer & operator<<(int8 value)
Definition: ByteBuffer.h:290
bool ReadBit()
Definition: ByteBuffer.h:186
void clear()
Definition: ByteBuffer.h:134
size_t _wpos
Definition: ByteBuffer.h:705
ByteBuffer & operator<<(const std::string &value)
Definition: ByteBuffer.h:327
size_t rpos(size_t rpos_)
Definition: ByteBuffer.h:443
void append(const ByteBuffer &buffer)
Definition: ByteBuffer.h:631
ByteBuffer & operator>>(int64 &value)
Definition: ByteBuffer.h:392
Definition: MessageBuffer.h:24
ByteBuffer & operator>>(double &value)
Definition: ByteBuffer.h:406
void WriteBits(T value, int32 bits)
Definition: ByteBuffer.h:198
T read()
Definition: ByteBuffer.h:484
octet_iterator append(uint32_t cp, octet_iterator result)
The library API - functions intended to be called by the users.
Definition: checked.h:73
void append(const char *src, size_t cnt)
Definition: ByteBuffer.h:603
size_t _rpos
Definition: ByteBuffer.h:705