pairpal
Loading...
Searching...
No Matches
NetworkMessage Class Reference

Class representing a message with a type and content. More...

#include <network_message.hpp>

Public Member Functions

 NetworkMessage (const NetworkMessageType &type)
 Constructs a NetworkMessage with a specified type.
 
 NetworkMessage (const std::string &str)
 Constructs a NetworkMessage from a string.
 
 ~NetworkMessage ()
 Destructor for the NetworkMessage class.
 
auto getType () const -> NetworkMessageType
 Gets the type of the message.
 
auto toJson () const -> nlohmann::json
 Converts the message to a JSON object.
 
auto toString () const -> std::string
 Converts the message to a string.
 
auto toZmqMessage () const -> std::unique_ptr< zmq::message_t >
 Converts the message to a ZMQ message.
 
void setUsername (const std::string &username)
 Sets the username associated with the message.
 
auto getUsername () const -> std::string
 Gets the username associated with the message.
 
void setPassword (const std::string &password)
 Sets the password associated with the message.
 
auto getPassword () const -> std::string
 Gets the password associated with the message.
 
void setTag (const std::string &tag)
 Sets the tag associated with the message.
 
auto getTag () const -> std::string
 Gets the tag associated with the message.
 
void setFrom (const std::string &from)
 Sets the sender of the message.
 
auto getFrom () const -> std::string
 Gets the sender of the message.
 
void setTo (const std::string &to)
 Sets the recipient of the message.
 
auto getTo () const -> std::string
 Gets the recipient of the message.
 
void setMessage (const std::string &message)
 Sets the message content.
 
auto getMessage () const -> std::string
 Gets the message content.
 
void setVector (const std::vector< std::string > &vector)
 Sets a vector of strings associated with the message.
 
auto getVector () const -> std::vector< std::string >
 Gets the vector of strings associated with the message.
 

Detailed Description

Class representing a message with a type and content.

Constructor & Destructor Documentation

◆ NetworkMessage() [1/2]

NetworkMessage::NetworkMessage ( const NetworkMessageType & type)
explicit

Constructs a NetworkMessage with a specified type.

Parameters
typeThe type of the message.

◆ NetworkMessage() [2/2]

NetworkMessage::NetworkMessage ( const std::string & str)
explicit

Constructs a NetworkMessage from a string.

Parameters
strThe string containing the message data.

Member Function Documentation

◆ getFrom()

auto NetworkMessage::getFrom ( ) const -> std::string
nodiscard

Gets the sender of the message.

Returns
The sender.

◆ getMessage()

auto NetworkMessage::getMessage ( ) const -> std::string
nodiscard

Gets the message content.

Returns
The message content.

◆ getPassword()

auto NetworkMessage::getPassword ( ) const -> std::string
nodiscard

Gets the password associated with the message.

Returns
The password.

◆ getTag()

auto NetworkMessage::getTag ( ) const -> std::string
nodiscard

Gets the tag associated with the message.

Returns
The tag.

◆ getTo()

auto NetworkMessage::getTo ( ) const -> std::string
nodiscard

Gets the recipient of the message.

Returns
The recipient.

◆ getType()

auto NetworkMessage::getType ( ) const -> NetworkMessageType
nodiscard

Gets the type of the message.

Returns
The type of the message.

◆ getUsername()

auto NetworkMessage::getUsername ( ) const -> std::string
nodiscard

Gets the username associated with the message.

Returns
The username.

◆ getVector()

auto NetworkMessage::getVector ( ) const -> std::vector< std::string >
nodiscard

Gets the vector of strings associated with the message.

Returns
The vector of strings.

◆ setFrom()

void NetworkMessage::setFrom ( const std::string & from)

Sets the sender of the message.

Parameters
fromThe sender to set.

◆ setMessage()

void NetworkMessage::setMessage ( const std::string & message)

Sets the message content.

Parameters
messageThe message content to set.

◆ setPassword()

void NetworkMessage::setPassword ( const std::string & password)

Sets the password associated with the message.

Parameters
passwordThe password to set.

◆ setTag()

void NetworkMessage::setTag ( const std::string & tag)

Sets the tag associated with the message.

Parameters
tagThe tag to set.

◆ setTo()

void NetworkMessage::setTo ( const std::string & to)

Sets the recipient of the message.

Parameters
toThe recipient to set.

◆ setUsername()

void NetworkMessage::setUsername ( const std::string & username)

Sets the username associated with the message.

Parameters
usernameThe username to set.

◆ setVector()

void NetworkMessage::setVector ( const std::vector< std::string > & vector)

Sets a vector of strings associated with the message.

Parameters
vectorThe vector of strings to set.

◆ toJson()

auto NetworkMessage::toJson ( ) const -> nlohmann::json
nodiscard

Converts the message to a JSON object.

Returns
The JSON representation of the message.

◆ toString()

auto NetworkMessage::toString ( ) const -> std::string
nodiscard

Converts the message to a string.

Returns
The string representation of the message.

◆ toZmqMessage()

auto NetworkMessage::toZmqMessage ( ) const -> std::unique_ptr< zmq::message_t >
nodiscard

Converts the message to a ZMQ message.

Returns
A unique pointer to the ZMQ message.

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