Capycore Engine  0.1.0
A simple and lightweight game engine written in C++ based on the Unity API architecture.
Loading...
Searching...
No Matches
network_message.h File Reference
#include <cstdint>
#include <cstring>
#include <vector>
Include dependency graph for network_message.h:
This graph shows which files directly or indirectly include this file:

Go to the source code of this file.

Classes

struct  MessageType
 Represents either a default or custom message identifier. More...
 
struct  MessageHeader
 Metadata describing the type and payload size of a message. More...
 
struct  Message
 Represents a complete network message including type and payload. More...
 
struct  MsgConnect
 
struct  MsgDisconnect
 

Enumerations

enum class  DefaultMessageTypes : uint16_t {
  CONNECT , DISCONNECT , CLIENT_CONNECT , HOST_DISCONNECT ,
  CLIENT_DISCONNECT , SNAPSHOT_FULL , SNAPSHOT_DELTA
}
 Built-in protocol message types used for core connection events. More...
 

Functions

template<typename T >
Message serialize_message (const T &data, MessageType type)
 Serializes a plain-old-data structure into a Message.
 
template<typename T >
deserialize_message (const Message &message)
 Deserializes a Message payload into a POD structure.
 

Enumeration Type Documentation

◆ DefaultMessageTypes

enum class DefaultMessageTypes : uint16_t
strong

Built-in protocol message types used for core connection events.

These message types represent the minimal set of messages required for establishing and maintaining multiplayer sessions.

Enumerator
CONNECT 
DISCONNECT 
CLIENT_CONNECT 
HOST_DISCONNECT 
CLIENT_DISCONNECT 
SNAPSHOT_FULL 
SNAPSHOT_DELTA 

Function Documentation

◆ deserialize_message()

template<typename T >
T deserialize_message ( const Message message)

Deserializes a Message payload into a POD structure.

Template Parameters
TExpected message structure type.
Parameters
messageThe incoming message containing serialized bytes.
Returns
A reconstructed instance of type T.

◆ serialize_message()

template<typename T >
Message serialize_message ( const T &  data,
MessageType  type 
)

Serializes a plain-old-data structure into a Message.

Template Parameters
TPOD type to serialize (must be trivially copyable).
Parameters
dataThe structure to serialize.
typeThe associated MessageType.
Returns
A fully constructed Message ready for transmission.