LRT13  1.0
 All Classes Namespaces Functions Variables Enumerations Enumerator
NetBuffer.h
1 #ifndef NET_BUFFER_H_
2 #define NET_BUFFER_H_
3 //stupid hack
4 #include "Includes.h"
5 #include <string.h>
6 #include <string>
7 
8 #ifdef __VXWORKS__
9 #include "../Utils/AsyncPrinter.h"
10 #endif
11 
12 #include "NetUtil.h"
13 
14 using namespace std;
15 
16 namespace Network
17 {
22  class NetBuffer
23  {
24  public:
28  NetBuffer();
29 
33  NetBuffer(const int bufferDefaultSize);
34 
38  NetBuffer(UINT8* buff, int len);
39 
43  ~NetBuffer();
44 
48  void Write(UINT8 c);
52  void Write(UINT8* c, UINT16 len);
56  void WriteRaw(UINT8* c, UINT16 len);
60  void Write(string str);
61  void Write(INT64 l);
62  void Write(UINT64 l);
66  void Write(INT32 i);
70  void Write(UINT32 i);
74  void Write(INT16 s);
78  void Write(double d);
82  void Write(float f);
86  void Write(bool b);
90  void WritePadBits();
91 
95  UINT8 ReadChar();
99  UINT8* ReadBytes();
103  string ReadStdString();
104  INT64 ReadInt64();
105  UINT64 ReadUInt64();
109  INT32 ReadInt32();
113  UINT32 ReadUInt32();
117  INT16 ReadInt16();
121  double ReadDouble();
125  float ReadFloat();
129  bool ReadBool();
133  void SkipPadBits();
134 
135  int GetBufferLength();
136 
140  int GetBytePos();
141 
145  int GetBitIndexInCurrentByte();
146 
150  UINT8* GetBuffer();
151 
152  //friend int NetPeer::Send(NetBuffer buff, NetChannel::Enum method, int channel);
153 
154  bool m_sent;
155  private:
156  void construct(UINT8* buff, int size);
157 
158  bool AssertBufferHasSpace(UINT32 bits);
159 
160  void InternalWriteByte(const UINT8 data, int bit_length);
161  void InternalWriteBytes(const UINT8 data[], int bytes);
162  void InternalWriteInteger(const UINT64 data, int bits);
163 
164  UINT8 InternalReadByte(int bit_length);
165  UINT8* InternalReadBytes(int length);
166  UINT64 InternalReadInteger(int bits);
167 
168  void FitBufferToSize(UINT32 bits);
169 
170  static const int kBufferResizeOverAllocateBytes; // TO-DO: make me configurable
171 
172  UINT8 * m_internalBuffer;
173  UINT32 m_internalBufferSize;
174  int m_internalBitPos;
175 
176  bool m_isReadOnly;
177  };
178 };
179 
180 #endif