forked from lizj3624/https-github.com-mogutt-TTServer
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathUtilPdu.h
More file actions
130 lines (111 loc) · 3.18 KB
/
Copy pathUtilPdu.h
File metadata and controls
130 lines (111 loc) · 3.18 KB
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
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
/*
* UtilPdu.h
*
* Created on: 2013-8-27
* Author: [email protected]
*/
#ifndef UTILPDU_H_
#define UTILPDU_H_
#include "ostype.h"
#include <set>
#include <map>
#include <list>
#include <string>
using namespace std;
#ifdef WIN32
#ifdef BUILD_PDU
#define DLL_MODIFIER __declspec(dllexport)
#else
#define DLL_MODIFIER __declspec(dllimport)
#endif
#else
#define DLL_MODIFIER
#endif
class DLL_MODIFIER CSimpleBuffer
{
public:
CSimpleBuffer();
~CSimpleBuffer();
uchar_t* GetBuffer() { return m_buffer; }
uint32_t GetAllocSize() { return m_alloc_size; }
uint32_t GetWriteOffset() { return m_write_offset; }
void IncWriteOffset(uint32_t len) { m_write_offset += len; }
void Extend(uint32_t len);
uint32_t Write(void* buf, uint32_t len);
uint32_t Read(void* buf, uint32_t len);
private:
uchar_t* m_buffer;
uint32_t m_alloc_size;
uint32_t m_write_offset;
};
class CByteStream
{
public:
CByteStream(uchar_t* buf, uint32_t len);
CByteStream(CSimpleBuffer* pSimpBuf, uint32_t pos);
~CByteStream() {}
unsigned char* GetBuf() { return m_pSimpBuf ? m_pSimpBuf->GetBuffer() : m_pBuf; }
uint32_t GetPos() { return m_pos; }
uint32_t GetLen() { return m_len; }
void Skip(uint32_t len) { m_pos += len; }
static int16_t ReadInt16(uchar_t* buf);
static uint16_t ReadUint16(uchar_t* buf);
static int32_t ReadInt32(uchar_t* buf);
static uint32_t ReadUint32(uchar_t* buf);
static void WriteInt16(uchar_t* buf, int16_t data);
static void WriteUint16(uchar_t* buf, uint16_t data);
static void WriteInt32(uchar_t* buf, int32_t data);
static void WriteUint32(uchar_t* buf, uint32_t data);
void operator << (int8_t data);
void operator << (uint8_t data);
void operator << (int16_t data);
void operator << (uint16_t data);
void operator << (int32_t data);
void operator << (uint32_t data);
void operator >> (int8_t& data);
void operator >> (uint8_t& data);
void operator >> (int16_t& data);
void operator >> (uint16_t& data);
void operator >> (int32_t& data);
void operator >> (uint32_t& data);
void WriteString(const char* str);
void WriteString(const char* str, uint32_t len);
char* ReadString(uint32_t& len);
void WriteData(uchar_t* data, uint32_t len);
uchar_t* ReadData(uint32_t& len);
private:
void _WriteByte(void* buf, uint32_t len);
void _ReadByte(void* buf, uint32_t len);
private:
CSimpleBuffer* m_pSimpBuf;
uchar_t* m_pBuf;
uint32_t m_len;
uint32_t m_pos;
};
#define ERROR_CODE_PARSE_FAILED 1
#define ERROR_CODE_WRONG_SERVICE_ID 2
#define ERROR_CODE_WRONG_COMMAND_ID 3
#define ERROR_CODE_ALLOC_FAILED 4
class CPduException {
public:
CPduException(uint32_t module_id, uint32_t command_id, uint32_t error_code, const char* error_msg)
{
m_module_id = module_id;
m_command_id = command_id;
m_error_code = error_code;
m_error_msg = error_msg;
}
virtual ~CPduException() {}
uint32_t GetModuleId() { return m_module_id; }
uint32_t GetCommandId() { return m_command_id; }
uint32_t GetErrorCode() { return m_error_code; }
char* GetErrorMsg() { return (char*)m_error_msg.c_str(); }
private:
uint32_t m_module_id;
uint32_t m_command_id;
uint32_t m_error_code;
string m_error_msg;
};
char* idtourl(uint32_t id);
uint32_t urltoid(const char* url);
#endif /* UTILPDU_H_ */