打包解包
#include <vector>
#include <iostream>
#include "compacket.h"
using namespace std;
char szBuf[4096];
const int INT = 4;
const int STRING = 100;
void EncodeMsg(char *pPos)
{
int tmp = 80000;
memcpy((void *) pPos, (void *) &tmp, INT);
pPos+=INT;
char Role[] = "艾迪";
memcpy((void *) pPos, (void *) &Role, STRING);
pPos+=STRING;
char strName[] = "aidigame";
memcpy((void *) pPos, (void *) &strName, STRING);
pPos += STRING;
}
void DecodeMsg(char *pPos)
{
int ItemTotal = 0;
memcpy((void *) &ItemTotal, pPos, INT);
pPos+=INT;
char Role[STRING];
memcpy((void *) &Role, pPos, STRING);
pPos+=STRING;
char strName[STRING];
memcpy((void *) &strName, pPos, STRING);
pPos+=STRING;
cout << ItemTotal << endl;
cout << Role << endl;
cout << strName << endl;
}
int main()
{
EncodeMsg(szBuf);
DecodeMsg(szBuf);
return 0;
}