LRT14  1.0
 All Classes Namespaces Functions Variables Enumerations Enumerator
NetBuffer.h
1 #ifndef RHESUS_NET_BUFFER_H_
2 #define RHESUS_NET_BUFFER_H_
3 
4 #include "Includes.h"
5 #include <string.h>
6 #include <string>
7 
8 #include "NetUtil.h"
9 
10 namespace Rhesus
11 {
12 namespace Messenger
13 {
18  class NetBuffer
19  {
20  public:
24  NetBuffer();
25 
29  NetBuffer(const int bufferDefaultSize);
30 
34  NetBuffer(UINT8* buff, int len);
35 
39  ~NetBuffer();
40 
44  void Write(UINT8 c);
48  void Write(UINT8* c, UINT16 len);
52  void WriteRaw(UINT8* c, UINT16 len);
56  void Write(string str);
57  void Write(INT64 l);
58  void Write(UINT64 l);
62  void Write(INT32 i);
66  void Write(UINT32 i);
70  void Write(INT16 s);
74  void Write(double d);
78  void Write(float f);
82  void Write(bool b);
86  void WritePadBits();
87 
91  UINT8 ReadChar();
95  UINT8* ReadBytes();
99  string ReadStdString();
100  INT64 ReadInt64();
101  UINT64 ReadUInt64();
105  INT32 ReadInt32();
109  UINT32 ReadUInt32();
113  INT16 ReadInt16();
117  double ReadDouble();
121  float ReadFloat();
125  bool ReadBool();
129  void SkipPadBits();
130 
131  int GetBufferLength();
132 
136  int GetBytePos();
137 
142 
146  UINT8* GetBuffer();
147 
148  //friend int NetPeer::Send(NetBuffer buff, NetChannel::Enum method, int channel);
149 
150  bool m_sent;
151  private:
152  void construct(UINT8* buff, int size);
153 
154  bool AssertBufferHasSpace(UINT32 bits);
155 
156  void InternalWriteByte(const UINT8 data, int bit_length);
157  void InternalWriteBytes(const UINT8 data[], int bytes);
158  void InternalWriteInteger(const UINT64 data, int bits);
159 
160  UINT8 InternalReadByte(int bit_length);
161  UINT8* InternalReadBytes(int length);
162  UINT64 InternalReadInteger(int bits);
163 
164  void FitBufferToSize(UINT32 bits);
165 
166  static const int kBufferResizeOverAllocateBytes; // TO-DO: make me configurable
167 
168  UINT8 * m_internalBuffer;
169  UINT32 m_internalBufferSize;
170  int m_internalBitPos;
171 
172  bool m_isReadOnly;
173  };
174 }
175 }
176 
177 #endif