pairpal
Loading...
Searching...
No Matches
network_message.hpp
1#ifndef NETWORK_MESSAGE_HPP
2#define NETWORK_MESSAGE_HPP
3
4#include <cstdint>
5#include <nlohmann/json.hpp>
6#include <zmq.hpp>
7
12enum class NetworkMessageType : uint8_t {
13 SUCCESS,
14 FAILURE,
15 UNKNOWN,
16 ADD_USER,
17 REMOVE_USER,
18 IS_EXIST_USER,
19 LIST_ALL_USERS,
20 AUTHENTICATE_USER,
21 ADD_USER_TAG,
22 REMOVE_USER_TAG,
23 GET_USER_TAGS,
24 SEND_MESSAGE,
25 GET_SENT_MESSAGES,
26 GET_RECEIVED_MESSAGES,
28 GET_PAIR
29};
30
36 public:
41 explicit NetworkMessage(const NetworkMessageType& type);
42
47 explicit NetworkMessage(const std::string& str);
48
53
58 [[nodiscard]] auto getType() const -> NetworkMessageType;
59
64 [[nodiscard]] auto toJson() const -> nlohmann::json;
65
70 [[nodiscard]] auto toString() const -> std::string;
71
76 [[nodiscard]] auto toZmqMessage() const -> std::unique_ptr<zmq::message_t>;
77
82 void setUsername(const std::string& username);
83
88 [[nodiscard]] auto getUsername() const -> std::string;
89
94 void setPassword(const std::string& password);
95
100 [[nodiscard]] auto getPassword() const -> std::string;
101
106 void setTag(const std::string& tag);
107
112 [[nodiscard]] auto getTag() const -> std::string;
113
118 void setFrom(const std::string& from);
119
124 [[nodiscard]] auto getFrom() const -> std::string;
125
130 void setTo(const std::string& to);
131
136 [[nodiscard]] auto getTo() const -> std::string;
137
142 void setMessage(const std::string& message);
143
148 [[nodiscard]] auto getMessage() const -> std::string;
149
154 void setVector(const std::vector<std::string>& vector);
155
160 [[nodiscard]] auto getVector() const -> std::vector<std::string>;
161
162 private:
163 NetworkMessageType type_;
164 nlohmann::json content_;
165};
166
167#endif // NETWORK_MESSAGE_HPP
Class representing a message with a type and content.
Definition network_message.hpp:35
NetworkMessage(const NetworkMessageType &type)
Constructs a NetworkMessage with a specified type.
auto getFrom() const -> std::string
Gets the sender of the message.
auto getMessage() const -> std::string
Gets the message content.
void setUsername(const std::string &username)
Sets the username associated with the message.
auto getTo() const -> std::string
Gets the recipient of the message.
auto toString() const -> std::string
Converts the message to a string.
void setMessage(const std::string &message)
Sets the message content.
auto getUsername() const -> std::string
Gets the username associated with the message.
void setTag(const std::string &tag)
Sets the tag associated with the message.
void setFrom(const std::string &from)
Sets the sender of the message.
auto getType() const -> NetworkMessageType
Gets the type of the message.
auto getPassword() const -> std::string
Gets the password associated with the message.
auto toJson() const -> nlohmann::json
Converts the message to a JSON object.
void setVector(const std::vector< std::string > &vector)
Sets a vector of strings associated with the message.
auto toZmqMessage() const -> std::unique_ptr< zmq::message_t >
Converts the message to a ZMQ message.
auto getVector() const -> std::vector< std::string >
Gets the vector of strings associated with the message.
NetworkMessage(const std::string &str)
Constructs a NetworkMessage from a string.
void setTo(const std::string &to)
Sets the recipient of the message.
void setPassword(const std::string &password)
Sets the password associated with the message.
auto getTag() const -> std::string
Gets the tag associated with the message.
~NetworkMessage()
Destructor for the NetworkMessage class.