R-Type
Distributed multiplayer game engine in C++
Loading...
Searching...
No Matches
NetworkEvent Class Reference

Event representing a network message. More...

#include <NetworkEvent.hpp>

Inheritance diagram for NetworkEvent:
Inheritance graph
Collaboration diagram for NetworkEvent:
Collaboration graph

Public Member Functions

 NetworkEvent (NetworkMessageType type, std::vector< uint8_t > data)
 Construct a network event.
 
NetworkMessageType getType () const
 Get the message type.
 
const std::vector< uint8_t > & getData () const
 Get the message data.
 
uint64_t getTimestamp () const
 Get the timestamp.
 
void setTimestamp (uint64_t timestamp)
 Set the timestamp.
 
const std::string & getMessageContent () const
 Get decoded message content (for convenience)
 
void setMessageContent (const std::string &content)
 Set decoded message content.
 
- Public Member Functions inherited from IEvent
virtual ~IEvent ()=default
 Virtual destructor.
 

Private Attributes

NetworkMessageType _type
 Type of network message.
 
std::vector< uint8_t > _data
 Raw binary data payload.
 
uint64_t _timestamp
 Timestamp for latency measurement.
 
std::string _messageContent
 Decoded message content (optional, for convenience)
 

Detailed Description

Event representing a network message.

NetworkEvent encapsulates network messages received from or sent to the server:

  • Message type (WORLD_STATE, PLAYER_INPUT, etc.)
  • Raw binary data payload
  • Decoded message content (for convenience)
  • Timestamp for latency measurement

Flow:

Note
Data is stored as raw bytes; interpretation depends on message type
Timestamp is set by Replicator for RTT calculation

Definition at line 50 of file NetworkEvent.hpp.

Constructor & Destructor Documentation

◆ NetworkEvent()

NetworkEvent::NetworkEvent ( NetworkMessageType  type,
std::vector< uint8_t >  data 
)
inline

Construct a network event.

Parameters
typeType of network message
dataRaw binary data payload

Definition at line 58 of file NetworkEvent.hpp.

Member Function Documentation

◆ getData()

const std::vector< uint8_t > & NetworkEvent::getData ( ) const
inline

Get the message data.

Returns
Reference to binary data payload

Definition at line 71 of file NetworkEvent.hpp.

References _data.

Referenced by GameLoop::handleNetworkMessage().

◆ getMessageContent()

const std::string & NetworkEvent::getMessageContent ( ) const
inline

Get decoded message content (for convenience)

Returns
Decoded message string

Definition at line 89 of file NetworkEvent.hpp.

References _messageContent.

◆ getTimestamp()

uint64_t NetworkEvent::getTimestamp ( ) const
inline

Get the timestamp.

Returns
Timestamp when message was received (milliseconds)

Definition at line 77 of file NetworkEvent.hpp.

References _timestamp.

◆ getType()

NetworkMessageType NetworkEvent::getType ( ) const
inline

Get the message type.

Returns
Type of network message

Definition at line 65 of file NetworkEvent.hpp.

References _type.

◆ setMessageContent()

void NetworkEvent::setMessageContent ( const std::string &  content)
inline

Set decoded message content.

Parameters
contentDecoded message

Definition at line 95 of file NetworkEvent.hpp.

References _messageContent.

Referenced by Replicator::networkThreadLoop().

◆ setTimestamp()

void NetworkEvent::setTimestamp ( uint64_t  timestamp)
inline

Set the timestamp.

Parameters
timestampTime when message was received

Definition at line 83 of file NetworkEvent.hpp.

References _timestamp.

Member Data Documentation

◆ _data

std::vector<uint8_t> NetworkEvent::_data
private

Raw binary data payload.

Definition at line 99 of file NetworkEvent.hpp.

Referenced by getData().

◆ _messageContent

std::string NetworkEvent::_messageContent
private

Decoded message content (optional, for convenience)

Definition at line 101 of file NetworkEvent.hpp.

Referenced by getMessageContent(), and setMessageContent().

◆ _timestamp

uint64_t NetworkEvent::_timestamp
private

Timestamp for latency measurement.

Definition at line 100 of file NetworkEvent.hpp.

Referenced by getTimestamp(), and setTimestamp().

◆ _type

NetworkMessageType NetworkEvent::_type
private

Type of network message.

Definition at line 98 of file NetworkEvent.hpp.

Referenced by getType().


The documentation for this class was generated from the following file: