Babel
Epitech's C++ VoIP project
Server
src
Utilities
Utils.hpp
Go to the documentation of this file.
1
//
2
// Created by cbihan on 10/10/2021.
3
//
4
5
#pragma once
6
7
#include <string>
8
#include "
Network/Message.hpp
"
9
#include "
Network/ITCPConnection.hpp
"
10
#include "
Network/RFCCodes.hpp
"
11
12
namespace
Babel::Utils
13
{
15
inline
Message<RFCCodes>
response
(uint16_t code, std::string description)
16
{
17
Message<RFCCodes>
m;
18
19
m.
header
.
codeId
=
RFCCodes::Response
;
20
m << code << static_cast<uint8_t>(description.size());
21
m << std::move(description);
22
return
m;
23
};
24
26
inline
Message<RFCCodes>
&
appendConnectionIpPort
(
Message<RFCCodes>
&m,
ITCPConnection<RFCCodes>
&c)
27
{
28
std::string address = c.
getPeerIp
();
29
uint16_t port = c.
getPeerPort
();
30
m << static_cast<uint8_t>(address.size()) << address << port;
31
return
m;
32
}
33
}
34
Message.hpp
Babel::Utils::appendConnectionIpPort
Message< RFCCodes > & appendConnectionIpPort(Message< RFCCodes > &m, ITCPConnection< RFCCodes > &c)
add the address and port of a tcp connection to a message
Definition:
Utils.hpp:26
Babel::Message::header
MessageHeader< T > header
The message metadata.
Definition:
Message.hpp:49
Babel::ITCPConnection::getPeerPort
virtual uint16_t getPeerPort() const =0
get the connected pair port
ITCPConnection.hpp
Babel::Message< RFCCodes >
RFCCodes.hpp
Babel::Utils
Definition:
Utilities.hpp:12
Babel::Utils::response
Message< RFCCodes > response(uint16_t code, std::string description)
Create a reply type message, used as a convenient way to quickly construct response description messa...
Definition:
Utils.hpp:15
Babel::MessageHeader::codeId
T codeId
The code id of the message to known what it's taking about.
Definition:
Message.hpp:23
Babel::RFCCodes::Response
@ Response
General purpose response.
Babel::ITCPConnection< RFCCodes >
Babel::ITCPConnection::getPeerIp
virtual std::string getPeerIp() const =0
Get the connected pair address.
Generated by
1.8.17