SOLA
Loading...
Searching...
No Matches
message.h
1// Copyright The SOLA Contributors
2//
3// Licensed under the MIT License.
4// For details on the licensing terms, see the LICENSE file.
5// SPDX-License-Identifier: MIT
6
7#ifndef SOLANET_NETWORK_UDP_MESSAGE_H_
8#define SOLANET_NETWORK_UDP_MESSAGE_H_
9
10#include <string>
11#include <utility>
12
13namespace solanet {
14class Message {
15public:
16 // Creates empty message
17 Message() = default;
18
19 Message(std::string ip, uint16_t port, std::string message)
20 : ip_(std::move(ip)), port_(port), message_(std::move(message)){};
21
22 Message(const std::string &endpoint, std::string message)
23 : ip_(endpoint.substr(0, endpoint.find(":"))),
24 port_(std::stoi(endpoint.substr(endpoint.find(":") + 1, endpoint.size()))),
25 message_(std::move(message)) {}
26
31 bool isEmpty() const { return ip_.empty() || message_.empty(); }
32
37 std::string getMessage() const { return message_; }
38
43 std::string getIp() const { return ip_; }
44
49 uint16_t getPort() const { return port_; }
50
51private:
52 std::string ip_{};
53 uint16_t port_ = 0;
54 std::string message_{};
55};
56} // namespace solanet
57
58#endif // SOLANET_NETWORK_UDP_MESSAGE_H_
Definition message.h:14
bool isEmpty() const
Definition message.h:31
std::string getMessage() const
Definition message.h:37
uint16_t getPort() const
Definition message.h:49
std::string getIp() const
Definition message.h:43