-
Notifications
You must be signed in to change notification settings - Fork 0
/
NetMessage.h
89 lines (76 loc) · 1.9 KB
/
NetMessage.h
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
#ifndef _NETMESSAGE_LKAJSLDFJASLDFJKLASDF_H__
#define _NETMESSAGE_LKAJSLDFJASLDFJKLASDF_H__
#include "string.h"
#include "assert.h"
#include "vector"
#include "stdio.h"
typedef unsigned char UInt8;
typedef signed char Int8;
#ifndef WIN32
typedef long long Int64;
#else
typedef __int64 Int64;
#endif
class MemBuffer;
class NetMessage
{
void checkBufSize(int size);
// -1 : unknown
// -2 : need 4 byte HeadSize
// >=0 : size known
int m_size;
int m_headSize; //2 or 4
int m_bufStartPos;
public:
NetMessage(int size = 512);
~NetMessage();
int getSize() const { return m_size; }
int getHeadSize() const { return m_headSize; }
void createBuf(int bufSize = 0);
char* getBuf(int pos);
char* getReadBuf();
int getReadCap();
int getSendCap();
void onReceive(int size);
void onSend(int size);
int getCurrentPos() const { return m_curPos; }
char* getCurrentBuf() { return getBuf(m_curPos); }
bool isEnd() const;
void ResetForSend() { m_curPos = m_bufStartPos; }
void ResetForRead() { m_curPos = m_bufStartPos + m_headSize; }
void wFloat(float v);
float rFloat();
void wShort(short v);
short rShort();
void wUShort(unsigned short v);
unsigned short rUShort();
void wInt(int v);
int rInt();
void wUInt(unsigned int v);
unsigned int rUInt();
void wInt8(Int8 v);
Int8 rInt8();
void wUInt8(UInt8 v);
UInt8 rUInt8();
void wInt64(Int64 v);
Int64 rInt64();
void wDouble(double v);
double rDouble();
void wBoolean(bool v);
bool rBoolean();
void wChar(char v);
char rChar();
void wString(const char* str, int sz);
const char* rString(int& sz);
void wRaw(const char* buf, int sz);
const char* rRaw(int sz);
void dump();
void beginForWrite();
void endForWrite();
private:
int m_curPos;
MemBuffer* m_buffer;
void setBufValue(char value);
char getBufValue();
};
#endif