-
Notifications
You must be signed in to change notification settings - Fork 85
/
Copy pathBasePacket.h
95 lines (80 loc) · 1.89 KB
/
BasePacket.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
90
91
92
93
94
/************************************************************************
* @file BasePacket.h
* @brief Network packet base class
* @author jiangwang
* @data 2019-1-15
* @version 0.1
************************************************************************/
#pragma once
#include "ByteBuffer.h"
class BasePacket : public ByteBuffer
{
public:
BasePacket();
~BasePacket();
virtual void zero();
virtual void release();
virtual void moveData(BasePacket * packet);
void shrink(int isize);
virtual int32 getHeadSize();
int32 getBodySize();
const char * getBodyData();
const char * readPointer();
void setWriteSize(int size);
int32 activeSize();
// lua call blob
std::string_view readData();
void writeData(std::string_view sv);
// read msg call
virtual int32 getMarkLen(); // message head mark length
virtual int getMsgType();
virtual bool isHeadFull();
// send msg call
virtual int32 sendSize();
virtual char * sendStream();
int readPos();
int writePos();
public:
//------->get
int8 getInt8();
uint8 getUint8();
int16 getInt16();
uint16 getUint16();
int32 getInt32();
uint32 getUint32();
int64 getInt64();
uint64 getUint64();
float getFloat();
double getDouble();
std::string getString();
//------->push
void pushInt8(int8 value);
void pushUint8(uint8 value);
void pushInt16(int16 value);
void pushUint16(uint16 value);
void pushInt32(int32 value);
void pushUint32(uint32 value);
void pushInt64(int64 value);
void pushUint64(uint64 value);
void pushFloat(float value);
void pushDouble(double value);
void pushString(std::string value);
protected:
template<typename T>
T popValue() {
T t;
*this >> t;
return t;
}
template<typename T>
T getValue(uint32 pos){
T value;
std::memcpy(&value, &(*_storage)[pos], sizeof(T));
EndianConvert(value);
return value;
}
template<typename T>
void setValue(uint32 pos, T t){
put(pos, t);
}
};