R-Type 0.1
Loading...
Searching...
No Matches
MessageHeader Struct Reference

Header placed in front of every message inside a connected packet. More...

#include <protocol/MessageHeader.hpp>

Public Member Functions

bool serialize (PacketWriter &writer) const
 Writes the header in network byte order.
 
bool deserialize (PacketReader &reader)
 Reads the header from a buffer.
 
MessageId getType () const
 Returns the message type.
 
void setType (MessageId type)
 Sets the message type.
 

Public Attributes

std::uint16_t size = 0
 Payload size in bytes, header excluded.
 

Static Public Attributes

static constexpr std::size_t HEADER_SIZE = 4
 Encoded size of the header, in bytes.
 

Detailed Description

Header placed in front of every message inside a connected packet.

Offset Size Field Description
0 2 type Message type identifier.
2 2 size Size of the payload that follows.

Member Function Documentation

◆ serialize()

bool MessageHeader::serialize ( PacketWriter & writer) const

Writes the header in network byte order.

Parameters
writerDestination buffer.
Returns
True on success, false if the buffer is full.

◆ deserialize()

bool MessageHeader::deserialize ( PacketReader & reader)

Reads the header from a buffer.

Parameters
readerSource buffer.
Returns
True on success, false if fewer than 4 bytes remain.

◆ getType()

MessageId MessageHeader::getType ( ) const

Returns the message type.

Returns
The message type identifier.

◆ setType()

void MessageHeader::setType ( MessageId type)

Sets the message type.

Parameters
typeThe message type identifier.