R-Type 0.1
Loading...
Searching...
No Matches
MessageHeader.hpp
1#pragma once
2
8#include "PacketReader.hpp"
9#include "PacketWriter.hpp"
10#include <cstddef>
11#include <cstdint>
12
14using MessageId = std::uint16_t;
15
25public:
31 bool serialize(PacketWriter &writer) const;
32
38 bool deserialize(PacketReader &reader);
39
44 MessageId getType() const;
45
50 void setType(MessageId type);
51
52 std::uint16_t size = 0;
53
55 static constexpr std::size_t HEADER_SIZE = 4;
56
57private:
58 MessageId _type = 0;
59};
60
Bounds checked reader of big-endian values over a byte buffer.
Definition PacketReader.hpp:15
Growable buffer of big-endian values, capped at MAX_PAYLOAD_SIZE.
Definition PacketWriter.hpp:16
std::uint16_t MessageId
Numeric identifier of a message type.
Definition MessageHeader.hpp:14
Header placed in front of every message inside a connected packet.
Definition MessageHeader.hpp:24
static constexpr std::size_t HEADER_SIZE
Encoded size of the header, in bytes.
Definition MessageHeader.hpp:55
bool deserialize(PacketReader &reader)
Reads the header from a buffer.
Definition MessageHeader.cpp:12
std::uint16_t size
Payload size in bytes, header excluded.
Definition MessageHeader.hpp:52
bool serialize(PacketWriter &writer) const
Writes the header in network byte order.
Definition MessageHeader.cpp:4
MessageId getType() const
Returns the message type.
Definition MessageHeader.cpp:25
void setType(MessageId type)
Sets the message type.
Definition MessageHeader.cpp:23