- Timestamp:
- Oct 10, 2018, 3:06:55 PM (6 years ago)
- Location:
- code/branches/mergeFS18
- Files:
-
- 2 edited
Legend:
- Unmodified
- Added
- Removed
-
code/branches/mergeFS18
- Property svn:mergeinfo changed
/code/branches/Masterserver_FS18 (added) merged: 11816,11829,11842,11856,11858,11880,11889,11905,11907,11910,11929-11930,11937,11962-11963,11973,11983,11990
- Property svn:mergeinfo changed
-
code/branches/mergeFS18/src/libraries/network/packet/ClassID.cc
r11071 r12027 46 46 47 47 48 ClassID::ClassID( ) : Packet(){48 ClassID::ClassID() : Packet() { 49 49 Identifier *id; 50 unsigned int nrOfClasses =0;51 unsigned int packetSize =2*sizeof(uint32_t); //space for the packetID and for the nrofclasses50 unsigned int nrOfClasses = 0; 51 unsigned int packetSize = 2 * sizeof(uint32_t); //space for the packetID and for the nrofclasses 52 52 uint32_t network_id; 53 flags_ = flags_ |PACKET_FLAGS_CLASSID;53 this->flags_ |= PACKET_FLAGS_CLASSID; 54 54 std::queue<std::pair<uint32_t, std::string>> tempQueue; 55 55 56 // calculate total needed size (for all strings and integers)57 for(const auto& mapEntry : IdentifierManager::getInstance().getIdentifierByStringMap()) {56 // calculate total needed size (for all strings and integers) 57 for(const auto& mapEntry : IdentifierManager::getInstance().getIdentifierByStringMap()) { 58 58 id = mapEntry.second; 59 59 if(id == nullptr || !id->hasFactory()) … … 64 64 tempQueue.push( std::pair<unsigned int, std::string>(network_id, classname) ); 65 65 ++nrOfClasses; 66 packetSize += (classname.size() +1)+sizeof(network_id)+sizeof(uint32_t);66 packetSize += (classname.size() + 1) + sizeof(network_id) + sizeof(uint32_t); 67 67 } 68 68 69 this->data_ =new uint8_t[ packetSize ];69 this->data_ = new uint8_t[ packetSize ]; 70 70 //set the appropriate packet id 71 71 assert(this->data_); 72 72 *(Type *)(this->data_ + _PACKETID ) = Type::ClassID; 73 73 74 uint8_t *temp =data_+sizeof(uint32_t);74 uint8_t *temp = this->data_ + sizeof(uint32_t); 75 75 // save the number of all classes 76 *(uint32_t*) temp = nrOfClasses;76 *(uint32_t*) temp = nrOfClasses; 77 77 temp += sizeof(uint32_t); 78 78 79 79 // now save all classids and classnames 80 80 std::pair<uint32_t, std::string> tempPair; 81 uint32_t tempsize = 2 *sizeof(uint32_t); // packetid and nrOfClasses81 uint32_t tempsize = 2 * sizeof(uint32_t); // packetid and nrOfClasses 82 82 while( !tempQueue.empty() ){ 83 83 tempPair = tempQueue.front(); 84 84 tempQueue.pop(); 85 *(uint32_t*) temp = tempPair.first;86 *(uint32_t*) (temp+sizeof(uint32_t)) = tempPair.second.size()+1;87 memcpy(temp +2*sizeof(uint32_t), tempPair.second.c_str(), tempPair.second.size()+1);88 temp +=2*sizeof(uint32_t)+tempPair.second.size()+1;89 tempsize +=2*sizeof(uint32_t)+tempPair.second.size()+1;85 *(uint32_t*) temp = tempPair.first; 86 *(uint32_t*) (temp+sizeof(uint32_t)) = tempPair.second.size() + 1; 87 memcpy(temp + 2 * sizeof(uint32_t), tempPair.second.c_str(), tempPair.second.size() + 1); 88 temp += 2 * sizeof(uint32_t) + tempPair.second.size() + 1; 89 tempsize += 2 * sizeof(uint32_t) + tempPair.second.size() + 1; 90 90 } 91 assert(tempsize ==packetSize);91 assert(tempsize == packetSize); 92 92 93 93 orxout(verbose_more, context::packets) << "classid packetSize is " << packetSize << endl; … … 104 104 } 105 105 106 uint32_t ClassID::getSize() const {107 uint8_t *temp = data_+sizeof(uint32_t); // packet identification106 uint32_t ClassID::getSize() const { 107 uint8_t *temp = this->data_ + sizeof(uint32_t); // packet identification 108 108 uint32_t totalsize = sizeof(uint32_t); // packet identification 109 uint32_t nrOfClasses = *(uint32_t*) temp;109 uint32_t nrOfClasses = *(uint32_t*) temp; 110 110 temp += sizeof(uint32_t); 111 111 totalsize += sizeof(uint32_t); // storage size for nr of all classes 112 112 113 for(unsigned int i=0; i <nrOfClasses; i++){114 totalsize += 2 *sizeof(uint32_t) + *(uint32_t*)(temp + sizeof(uint32_t));115 temp += 2 *sizeof(uint32_t) + *(uint32_t*)(temp + sizeof(uint32_t));113 for(unsigned int i=0; i < nrOfClasses; i++) { 114 totalsize += 2 * sizeof(uint32_t) + *(uint32_t*) (temp + sizeof(uint32_t)); 115 temp += 2 * sizeof(uint32_t) + *(uint32_t*)(temp + sizeof(uint32_t)); 116 116 } 117 117 return totalsize; 118 118 } 119 119 120 121 bool ClassID::process(orxonox::Host* host){ 120 bool ClassID::process(orxonox::Host* host) { 122 121 int nrOfClasses; 123 uint8_t *temp = data_+sizeof(uint32_t); //skip the packetid122 uint8_t *temp = this->data_ + sizeof(uint32_t); //skip the packetid 124 123 uint32_t networkID; 125 124 uint32_t stringsize; 126 125 unsigned char *classname; 127 128 126 129 127 //clear the map of network ids … … 134 132 Identifier *id; 135 133 // read the total number of classes 136 nrOfClasses = *(uint32_t*) temp;134 nrOfClasses = *(uint32_t*) temp; 137 135 temp += sizeof(uint32_t); 138 136 139 for( int i =0; i<nrOfClasses; i++){140 networkID = *(uint32_t*) temp;141 stringsize = *(uint32_t*) (temp+sizeof(uint32_t));142 classname = temp +2*sizeof(uint32_t);143 id =ClassByString( std::string((const char*)classname) );137 for( int i = 0; i < nrOfClasses; i++) { 138 networkID = *(uint32_t*) temp; 139 stringsize = *(uint32_t*) (temp + sizeof(uint32_t)); 140 classname = temp + 2 * sizeof(uint32_t); 141 id = ClassByString( std::string((const char*) classname) ); 144 142 orxout(internal_info, context::packets) << "processing classid: " << networkID << " name: " << classname << " id: " << id << endl; 145 if(id ==nullptr){143 if(id == nullptr) { 146 144 orxout(user_error, context::packets) << "Received a bad classname" << endl; 147 145 abort(); 148 146 } 149 147 id->setNetworkID( networkID ); 150 temp += 2 *sizeof(uint32_t) + stringsize;148 temp += 2 * sizeof(uint32_t) + stringsize; 151 149 } 152 150 delete this;
Note: See TracChangeset
for help on using the changeset viewer.