[go: up one dir, main page]

Menu

[r69]: / gmp / message.cpp  Maximize  Restore  History

Download this file

128 lines (96 with data), 3.0 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
/*****************************************************************************
Copyright © 2006, 2007, The Board of Trustees of the University of Illinois.
All Rights Reserved.
Group Messaging Protocol (GMP)
National Center for Data Mining (NCDM)
University of Illinois at Chicago
http://www.ncdm.uic.edu/
GMP is free software: you can redistribute it and/or modify it under
the terms of the GNU General Public License as published by the Free
Software Foundation, either version 3 of the License, or (at your option)
any later version.
GMP is distributed in the hope that it will be useful, but WITHOUT ANY
WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details.
You should have received a copy of the GNU General Public License along
with this program. If not, see <http://www.gnu.org/licenses/>.
*****************************************************************************/
/*****************************************************************************
written by
Yunhong Gu [gu@lac.uic.edu], last updated 01/25/2007
*****************************************************************************/
#include <string.h>
#include <message.h>
using namespace cb;
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);
}