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

49 lines
No EOL
1.2 KiB
C++

#pragma once
#include <array>
#include <cstdint>
namespace drp::packet {
enum class SecurityMode {
PLAIN = 0x00,
AES = 0x01,
RSA = 0x02,
};
// the maximum data length
// a packet can't be larger than 65565 (uint16 max)
// reserve some space for metadata and settings
constexpr std::uint16_t dataLength = 65504;
/**
* 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.
*/
struct GenericPacketContent {
std::uint8_t eventType;
std::array<std::uint8_t, dataLength> data;
};
/**
* A generic packet that can be transmitted through the network.
* @param channel the channel of the packet. Two system can be created inside a same network by using different
* channels value. "0" is used for "broadcast" message across networks.
* @param securityMode the type of security used in the packet.
* @param _content the content of the packet. It is encrypted accordingly to the securityMode.
*/
struct GenericPacket {
std::uint8_t channel;
std::uint8_t securityMode;
GenericPacketContent _content;
[[nodiscard]] GenericPacketContent getContent() const;
void setContent(const GenericPacketContent& content);
};
}