- Timestamp:
- Jan 29, 2013, 7:04:22 PM (12 years ago)
- Branches:
- master
- Children:
- ad5d122
- Parents:
- 88cdae2
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
common/Player.cpp
r88cdae2 r80b3f94 51 51 void Player::serialize(char* buffer) 52 52 { 53 ostringstream oss; 54 55 oss << this->id; 56 oss << this->name; 57 oss << '\0'; 58 oss << this->pos.x; 59 oss << this->pos.y; 60 61 memcpy(buffer, oss.str().c_str(), oss.str().length()); 53 memcpy(buffer, &this->id, 4); 54 strcpy(buffer+4, this->name.c_str()); 55 memcpy(buffer+4+this->name.length(), &this->pos.x, 4); 56 memcpy(buffer+8+this->name.length(), &this->pos.y, 4); 62 57 } 63 58 64 59 void Player::deserialize(char* buffer) 65 60 { 66 istringstream iss; 67 iss.str(buffer); 61 char test[256]; 68 62 69 iss >> this->id; 70 iss >> this->name; 71 iss >> this->pos.x; 72 iss >> this->pos.y; 63 memcpy(&this->id, buffer, 4); 64 strcpy(test, buffer+4); 65 memcpy(&this->pos.x, buffer+4+strlen(test), 4); 66 memcpy(&this->pos.y, buffer+8+strlen(test), 4); 67 68 cout << "id: " << this->id << endl; 69 cout << "name: " << test << endl; 70 cout << "x: " << this->pos.x << endl; 71 cout << "y: " << this->pos.y << endl; 73 72 } 74 73
Note:
See TracChangeset
for help on using the changeset viewer.