本文整理汇总了C++中PacketHdr::setShortIntegerInfo方法的典型用法代码示例。如果您正苦于以下问题:C++ PacketHdr::setShortIntegerInfo方法的具体用法?C++ PacketHdr::setShortIntegerInfo怎么用?C++ PacketHdr::setShortIntegerInfo使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类PacketHdr
的用法示例。
在下文中一共展示了PacketHdr::setShortIntegerInfo方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: Packet
/**
* Create a DATA message. seqNum = sequence number of the packet
*/
Packet *Message::make_data_packet(int seqNum){
Packet *data_packet;
data_packet = new Packet();
//Header
PacketHdr *hdr = data_packet->accessHeader();
hdr->setIntegerInfo(SENDER_ID, ID_POS);
hdr->setShortIntegerInfo(DATA_MESSAGE_TYPE, TYPE_POS);
hdr->setIntegerInfo(seqNum,SEQNUM_POS); //sequence number
if(seqNum == number_of_packets_){
hdr->setShortIntegerInfo(1,EOF_POS);
}else{
hdr->setShortIntegerInfo(0,EOF_POS);
}
//Payload
int payload_size;
if(seqNum == number_of_packets_){
payload_size = length_ - (number_of_packets_ - 1) * DATA_SIZE;
}
else{
payload_size = DATA_SIZE;
}
char *data_chunk = new char[payload_size];
//read the file
ifstream f1(filename_);
f1.seekg(0, ios::end);
int pos = (seqNum - 1) * DATA_SIZE;
f1.seekg(pos);
f1.read(data_chunk, payload_size);
f1.close();
data_packet->fillPayload(payload_size, data_chunk);
return data_packet;
}
示例2: Packet
Packet *Message::make_response_packet(int CID, int HID, const char *filename){
Packet * response_packet;
response_packet = new Packet();
//get some info of the file
//read file
ifstream f1(filename);
f1.seekg(0, ios::end);
int len = (int)f1.tellg();
f1.seekg(0, f1.beg);
char *datachunk = new char[len];
f1.read(datachunk, len);
f1.close();
//Header
PacketHdr *hdr = response_packet->accessHeader();
hdr->setOctet(TYPE_RESPONSE, POS_TYPE );
hdr->setOctet(CID, POS_CID );
hdr->setOctet(HID, POS_HID );
hdr->setShortIntegerInfo(len, POS_SIZE);
// fill payload by content...
response_packet->fillPayload(len, datachunk);
return response_packet;
}