Packet.h 810 B

123456789101112131415161718192021222324252627282930313233343536
  1. #ifndef PACKET_H
  2. #define PACKET_H
  3. #include "common/network/ENet.h"
  4. class Packet {
  5. ENetPacket* packet;
  6. int readIndex;
  7. bool error;
  8. public:
  9. typedef char int8;
  10. typedef short int16;
  11. typedef int int32;
  12. static_assert(sizeof (int8) == 1, "size of int8 must be 1 byte");
  13. static_assert(sizeof (int16) == 2, "size of int16 must be 2 byte");
  14. static_assert(sizeof (int32) == 4, "size of int32 must be 4 byte");
  15. Packet(ENetPacket* packet);
  16. ~Packet();
  17. Packet(const Packet&) = delete;
  18. Packet& operator=(const Packet&) = delete;
  19. Packet(Packet&&) = delete;
  20. Packet& operator=(Packet&&) = delete;
  21. bool hasData() const;
  22. bool hasError() const;
  23. void read(void* buffer, int length);
  24. int8 read8();
  25. int16 read16();
  26. int32 read32();
  27. };
  28. #endif