void splitForSend(const INFPacket& src, PacketList& destList){ //clear out queue destList.clear(); //segments std::vector<Uint8> tmp; tmp.reserve(maxSendSize); size_t dataIndex = 0; Uint16 len = 0; Uint8 len_buff[2]; unsigned int remaining = 0; while( dataIndex < src.data.size() ){ // Packet header if( dataIndex == 0 ){ tmp.push_back(ControlByte::START.getVal() ); } else { tmp.push_back(ControlByte::CONTINUE.getVal() ); } // data //minus 2 from maxSendSize for the START/END //minus 2 again, becuase 2 bytes are used to store the length // of this segment //how much of the input data is left to be packed remaining = src.data.size() - dataIndex; //the length of the next segment if( remaining > (maxSendSize-4) ){ len = (maxSendSize-4); } else { len = remaining; } //insert the length of this segment SDLNet_Write16(len, len_buff); tmp.push_back( len_buff[0] ); tmp.push_back( len_buff[1] ); //write the actual data for(int i = 0; i < len; ++i){ tmp.push_back( src.data[dataIndex] ); ++dataIndex; } // Packet footer if( dataIndex == src.getLength() ){ tmp.push_back(ControlByte::END.getVal() ); } else { tmp.push_back(ControlByte::WAIT_MORE.getVal() ); } // Put the packet on the list destList.push_back(tmp); tmp.clear(); } }