M2-PT-DRP/source/packets/base/PacketContent.hpp

35 lines
809 B
C++

#pragma once
#include <cstdint>
#include <limits>
#include <vector>
#include "behavior/events/types.hpp"
namespace drp::packet::base {
// The maximum length of a packet. Cannot be larger than 65565 (uint16 max).
constexpr std::uint16_t maxPacketLength = std::numeric_limits<std::uint16_t>::max();
/**
* The content of a generic packet.
* @param eventType the type of event that the packet want to trigger.
* @param data the data of the event.
*/
class PacketContent {
public:
PacketContent();
PacketContent(event::EventType eventType, const std::vector<std::uint8_t>& data);
[[nodiscard]] std::vector<std::uint8_t> serialize() const;
static PacketContent deserialize(std::vector<std::uint8_t>& data);
event::EventType eventType {};
std::vector<std::uint8_t> data;
};
}