2026-02-02 12:24:50 -08:00
|
|
|
#pragma once
|
|
|
|
|
|
|
|
|
|
#include <vector>
|
|
|
|
|
#include <cstdint>
|
|
|
|
|
#include <string>
|
|
|
|
|
|
|
|
|
|
namespace wowee {
|
|
|
|
|
namespace network {
|
|
|
|
|
|
|
|
|
|
class Packet {
|
|
|
|
|
public:
|
|
|
|
|
Packet() = default;
|
|
|
|
|
explicit Packet(uint16_t opcode);
|
|
|
|
|
Packet(uint16_t opcode, const std::vector<uint8_t>& data);
|
2026-02-22 06:38:41 -08:00
|
|
|
Packet(uint16_t opcode, std::vector<uint8_t>&& data);
|
2026-02-02 12:24:50 -08:00
|
|
|
|
|
|
|
|
void writeUInt8(uint8_t value);
|
|
|
|
|
void writeUInt16(uint16_t value);
|
|
|
|
|
void writeUInt32(uint32_t value);
|
|
|
|
|
void writeUInt64(uint64_t value);
|
2026-02-05 14:01:26 -08:00
|
|
|
void writeFloat(float value);
|
2026-02-02 12:24:50 -08:00
|
|
|
void writeString(const std::string& value);
|
|
|
|
|
void writeBytes(const uint8_t* data, size_t length);
|
|
|
|
|
|
|
|
|
|
uint8_t readUInt8();
|
|
|
|
|
uint16_t readUInt16();
|
|
|
|
|
uint32_t readUInt32();
|
|
|
|
|
uint64_t readUInt64();
|
|
|
|
|
float readFloat();
|
|
|
|
|
std::string readString();
|
|
|
|
|
|
|
|
|
|
uint16_t getOpcode() const { return opcode; }
|
|
|
|
|
const std::vector<uint8_t>& getData() const { return data; }
|
|
|
|
|
size_t getReadPos() const { return readPos; }
|
|
|
|
|
size_t getSize() const { return data.size(); }
|
2026-03-25 12:42:56 -07:00
|
|
|
size_t getRemainingSize() const { return data.size() - readPos; }
|
2026-03-25 12:46:44 -07:00
|
|
|
bool hasFullPackedGuid() const {
|
|
|
|
|
if (readPos >= data.size()) return false;
|
|
|
|
|
uint8_t mask = data[readPos];
|
|
|
|
|
size_t guidBytes = 1;
|
|
|
|
|
for (int bit = 0; bit < 8; ++bit)
|
|
|
|
|
if (mask & (1u << bit)) ++guidBytes;
|
|
|
|
|
return getRemainingSize() >= guidBytes;
|
|
|
|
|
}
|
2026-02-02 12:24:50 -08:00
|
|
|
void setReadPos(size_t pos) { readPos = pos; }
|
|
|
|
|
|
|
|
|
|
private:
|
|
|
|
|
uint16_t opcode = 0;
|
|
|
|
|
std::vector<uint8_t> data;
|
|
|
|
|
size_t readPos = 0;
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
} // namespace network
|
|
|
|
|
} // namespace wowee
|