📄 _msg_head.cpp
字号:
// _MSG_Head.cpp: implementation of the C_MSG_Head class.
//
//////////////////////////////////////////////////////////////////////
#include "stdafx.h"
#include "_MSG_Head.h"
#include "net_protocal.h"
//////////////////////////////////////////////////////////////////////
// Construction/Destruction
//////////////////////////////////////////////////////////////////////
EMSP2_0::C_MSG_Head::C_MSG_Head()
{
mh.Seqnum++;
bsize=0;
}
EMSP2_0::C_MSG_Head::~C_MSG_Head()
{
}
void EMSP2_0::C_MSG_Head::TranFromchars(char chars[], int len, MsgHead &mhv)
{
char aResult[13];
Utility::fillchar(aResult,0);
for(int i=0;i<len;i++)
{
aResult[i]=chars[i];
}
char ar2[2];
char ar4[4];
Utility::fillchar(ar2,0);
//get Total length;
ar2[0]=aResult[0];
ar2[1]=aResult[1];
mh.Total_length=Utility::charsToShort(ar2);
Utility::fillchar(ar2,0);
//get Command_ID
ar2[0]=aResult[2];
ar2[1]=aResult[3];
mhv.Command_ID=Utility::charsToShort(ar2);
mhv.Crypt=aResult[4];
Utility::fillchar(ar4,0);
ar4[0]=aResult[5];
ar4[1]=aResult[6];
ar4[2]=aResult[7];
ar4[3]=aResult[8];
mhv.Seqnum=Utility::charsToInt(ar4);
Utility::fillchar(ar4,0);
ar4[0]=aResult[9];
ar4[1]=aResult[10];
ar4[2]=aResult[11];
ar4[3]=aResult[12];
mhv.UserNo=Utility::charsToInt(ar4);
bsize=13;
}
EMSP2_0::C_MSG_Head::C_MSG_Head(C_MSG_Head &right)
{
mh.Total_length=right.mh.Total_length;
mh.Command_ID=right.mh.Command_ID;
mh.Crypt=right.mh.Crypt;
mh.Seqnum=right.mh.Seqnum;
mh.UserNo=right.mh.UserNo;
}
EMSP2_0::C_MSG_Head::C_MSG_Head(char *chars)
{
TranFromchars(chars,13,mh);
}
/*C_MSG_Head EMSP2_0::C_MSG_Head::operator =(char *chars)
{
TranFromchars(right,13,*this);
return *this;
}
EMSP2_0::C_MSG_Head C_MSG_Head::operator =(C_MSG_Head &right)
{
Total_length=right.Total_length;
Command_ID=right.Command_ID;
Crypt=right.Crypt;
Seqnum=right.Seqnum;
UserNo=right.UserNo;
return *this;
}
bool EMSP2_0::C_MSG_Head::operator ==(C_MSG_Head &right)
{
bool flag=(Total_length==right.Total_length)&&
(Command_ID==right.Command_ID)&&(Crypt==right.Crypt)
&&(Seqnum=right.Seqnum)&&(UserNo==right.UserNo);
return flag;
}
bool EMSP2_0::C_MSG_Head::operator !=(C_MSG_Head &right)
{
return !(*this==right);
}
*/
char* EMSP2_0::C_MSG_Head::getBytes()
{
char sTotal_length[2];
Utility::shortTochars(mh.Total_length,sTotal_length);
result[0]=sTotal_length[0];
result[1]=sTotal_length[1];
//delete sTotal_length;
char sCommand_ID[2];
Utility::shortTochars(mh.Command_ID,sCommand_ID);
result[2]=sCommand_ID[0];
result[3]=sCommand_ID[1];
result[4]=mh.Crypt;
char sSeqNum[4];
Utility::intTochars(mh.Seqnum,sSeqNum);
result[5]=sSeqNum[0];
result[6]=sSeqNum[1];
result[7]=sSeqNum[2];
result[8]=sSeqNum[3];
char sUserNo[4];
Utility::intTochars(mh.UserNo,sUserNo);
result[9]=sUserNo[0];
result[10]=sUserNo[1];
result[11]=sUserNo[2];
result[12]=sUserNo[3];
bsize=13;
return result;
}
EMSP2_0::MsgHead* EMSP2_0::C_MSG_Head::value()
{
return &mh;
}
void EMSP2_0::C_MSG_Head::TransFromchars(char *chars, int len)
{
TranFromchars(chars,len,mh);
}
void EMSP2_0::C_MSG_Head::proc()
{
char sTotal_length[2];
Utility::shortTochars(mh.Total_length,sTotal_length);
this->result[0]=sTotal_length[0];
this->result[1]=sTotal_length[1];
//delete[] sTotal_length;
char sCommand_ID[2];
Utility::shortTochars(mh.Command_ID,sCommand_ID);
this->result[2]=sCommand_ID[0];
this->result[3]=sCommand_ID[1];
this->result[4]=mh.Crypt;
char sSeqNum[4];
Utility::intTochars(mh.Seqnum,sSeqNum);
this->result[5]=sSeqNum[0];
this->result[6]=sSeqNum[1];
this->result[7]=sSeqNum[2];
this->result[8]=sSeqNum[3];
char sUserNo[4];
Utility::intTochars(mh.UserNo,sUserNo);
this->result[9]=sUserNo[0];
this->result[10]=sUserNo[1];
this->result[11]=sUserNo[2];
this->result[12]=sUserNo[3];
}
EMSP2_0::C_MSG_Head::C_MSG_Head(MsgHead value1)
{
mh=value1;
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -