[go: up one dir, main page]

Menu

[r8]: / comm / message.cpp  Maximize  Restore  History

Download this file

96 lines (74 with data), 1.7 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
#include <string.h>
#include <message.h>
CUserMessage::CUserMessage():
m_iDataLength(0),
m_iBufLength(65536)
{
m_pcBuffer = new char[m_iBufLength];
}
CUserMessage::CUserMessage(const int& len):
m_iDataLength(0),
m_iBufLength(len)
{
if (m_iBufLength < 4)
m_iBufLength = 4;
m_pcBuffer = new char[m_iBufLength];
}
CUserMessage::CUserMessage(const CUserMessage& msg):
m_iDataLength(msg.m_iDataLength),
m_iBufLength(msg.m_iBufLength)
{
m_pcBuffer = new char[m_iBufLength];
memcpy(m_pcBuffer, msg.m_pcBuffer, m_iDataLength + 4);
}
CUserMessage::~CUserMessage()
{
delete [] m_pcBuffer;
}
int CUserMessage::resize(const int& len)
{
m_iBufLength = len;
if (m_iBufLength < m_iDataLength)
m_iBufLength = m_iDataLength;
char* temp = new char[m_iBufLength];
memcpy(temp, m_pcBuffer, m_iDataLength);
delete [] m_pcBuffer;
m_pcBuffer = temp;
return m_iBufLength;
}
int32_t CRTMsg::getType() const
{
return *(int32_t*)m_pcBuffer;
}
void CRTMsg::setType(const int32_t& type)
{
*(int32_t*)m_pcBuffer = type;
}
char* CRTMsg::getData() const
{
return m_pcBuffer + 4;
}
void CRTMsg::setData(const int& offset, const char* data, const int& len)
{
while (4 + offset + len > m_iBufLength)
resize(m_iBufLength << 1);
memcpy(m_pcBuffer + 4 + offset, data, len);
}
int32_t CCBMsg::getType() const
{
return *(int32_t*)m_pcBuffer;
}
void CCBMsg::setType(const int32_t& type)
{
*(int32_t*)m_pcBuffer = type;
}
char* CCBMsg::getData() const
{
return m_pcBuffer + 4;
}
void CCBMsg::setData(const int& offset, const char* data, const int& len)
{
while (4 + offset + len > m_iBufLength)
resize(m_iBufLength << 1);
memcpy(m_pcBuffer + 4 + offset, data, len);
}