📄 packetanswer.cpp
字号:
/*
This file is part of SWAIN (http://sourceforge.net/projects/swain).
Copyright (C) 2006 Daniel Lindstr鰉 and Daniel Nilsson
This program 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 2
of the License, or (at your option) any later version.
This program 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, write to the Free Software
Foundation, Inc., 51 Franklin Street, Fifth Floor,
Boston, MA 02110-1301, USA.
*/
#include "StdAfx.h"
#include "PacketAnswer.h"
#include "packetid.h"
PacketAnswer::PacketAnswer(void){
this->result = NULL;
this->result_size = 0;
this->flag = 0;
}
PacketAnswer::PacketAnswer(int flag, int *result, int result_size){
this->result = result;
this->result_size = result_size;
this->flag = flag;
}
PacketAnswer::~PacketAnswer(void){
}
void PacketAnswer::read(Socket *s, int size){
this->result_size = (size-sizeof(int)) / sizeof(int);
this->result = (int *)malloc(this->result_size*sizeof(int));
s->receiveInt(&this->flag);
for(int i=0; i < this->result_size; i++)
s->receiveInt(&this->result[i]);
}
void PacketAnswer::write(Socket *s){
s->sendInt(this->flag);
for(int i=0; i<this->result_size; i++)
s->sendInt(this->result[i]);
}
int PacketAnswer::getSize(void){
return(sizeof(int)*(this->result_size+1));
}
int PacketAnswer::getId(void){
return(PACKET_ANSWER);
}
const int *PacketAnswer::getResult(void){
return(this->result);
}
int PacketAnswer::getResultSize(void) {
return result_size;
}
int PacketAnswer::getFlag(){
return(this->flag);
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -