de serialize packet from file must read from a binary file if we use plain "unpack"
| 362 | // de serialize packet from file |
| 363 | // must read from a binary file if we use plain "unpack" |
| 364 | bool PingPacket::readFromFile(std::istream& in) { |
| 365 | if (!in) { return false; } |
| 366 | |
| 367 | char buffer[PingPacket::PacketSize], serverVersion[9]; |
| 368 | uint16_t len, code; |
| 369 | |
| 370 | // get packet |
| 371 | in.read(buffer, sizeof(buffer)); |
| 372 | if ((size_t)in.gcount() < sizeof(buffer)) { |
| 373 | return false; |
| 374 | } |
| 375 | |
| 376 | // decode header |
| 377 | void* buf = buffer; |
| 378 | buf = nboUnpackUInt16(buf, len); |
| 379 | buf = nboUnpackUInt16(buf, code); |
| 380 | |
| 381 | // make sure we got the rest of the message |
| 382 | if (len != in.gcount() - 4) { |
| 383 | return false; |
| 384 | } |
| 385 | |
| 386 | // unpack body of reply |
| 387 | buf = unpack(buf, serverVersion); |
| 388 | |
| 389 | // compare protocol version against my protocol version. |
| 390 | return (strncmp(serverVersion, getServerVersion(), 8) == 0); |
| 391 | } |
| 392 | |
| 393 | // Local Variables: *** |
| 394 | // mode: C++ *** |
nothing calls this directly
no test coverage detected