39 lines
1.1 KiB
C++
39 lines
1.1 KiB
C++
#pragma once
|
|
|
|
#include <cstdint>
|
|
|
|
#include "Context.hpp"
|
|
#include "PacketContent.hpp"
|
|
#include "SecurityMode.hpp"
|
|
|
|
|
|
namespace drp::packet::base {
|
|
|
|
|
|
/**
|
|
* 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.
|
|
*/
|
|
class Packet {
|
|
public:
|
|
Packet();
|
|
explicit Packet(std::uint8_t channel, SecurityMode securityMode, const std::vector<uint8_t>& content);
|
|
|
|
[[nodiscard]] PacketContent getContent(const Context& context) const;
|
|
void setContent(const Context& context, SecurityMode securityMode, const PacketContent& packetContent);
|
|
|
|
[[nodiscard]] std::vector<std::uint8_t> serialize() const;
|
|
static Packet deserialize(std::vector<std::uint8_t>& data);
|
|
|
|
std::uint8_t channel {};
|
|
|
|
private:
|
|
SecurityMode securityMode {};
|
|
std::vector<std::uint8_t> content;
|
|
};
|
|
|
|
|
|
}
|