Diag-Client-Lib
udp_message.h
Go to the documentation of this file.
1 /* Diagnostic Client library
2  * Copyright (C) 2024 Avijit Dey
3  *
4  * This Source Code Form is subject to the terms of the Mozilla Public
5  * License, v. 2.0. If a copy of the MPL was not distributed with this
6  * file, You can obtain one at http://mozilla.org/MPL/2.0/.
7  */
8 #ifndef DIAG_CLIENT_LIB_LIB_BOOST_SUPPORT_SOCKET_UDP_UDP_MESSAGE_H_
9 #define DIAG_CLIENT_LIB_LIB_BOOST_SUPPORT_SOCKET_UDP_UDP_MESSAGE_H_
10 
11 #include <memory>
12 #include <string>
13 #include <string_view>
14 #include <utility>
15 #include <vector>
16 
17 #include "core/include/span.h"
18 
19 namespace boost_support {
20 namespace socket {
21 namespace udp {
22 
26 constexpr std::uint8_t kDoipUdpResSize{40u};
27 
31 class UdpMessage final {
32  public:
36  using BufferType = std::vector<uint8_t>;
37 
41  using IpAddressType = std::string_view;
42 
43  public:
47  UdpMessage(IpAddressType host_ip_address, std::uint16_t host_port_number)
48  : rx_buffer_{},
49  tx_buffer_{},
50  host_ip_address_{host_ip_address},
51  host_port_number_{host_port_number} {}
52 
62  UdpMessage(IpAddressType host_ip_address, std::uint16_t host_port_number, BufferType payload)
63  : rx_buffer_{std::move(payload)},
64  tx_buffer_{},
65  host_ip_address_{host_ip_address},
66  host_port_number_{host_port_number} {}
67 
68  UdpMessage(UdpMessage &&other) noexcept = default;
69  UdpMessage &operator=(UdpMessage &&other) noexcept = default;
70 
71  UdpMessage(const UdpMessage &other) = delete;
72  UdpMessage &operator=(const UdpMessage &other) = delete;
73 
77  virtual ~UdpMessage() = default;
78 
84 
89  std::uint16_t GetHostPortNumber() const { return host_port_number_; }
90 
96 
102 
107  BufferType const &GetTxBuffer() const { return tx_buffer_; }
108 
109  private:
114 
119 
124 
128  std::uint16_t host_port_number_;
129 };
130 
134 using UdpMessageConstPtr = std::unique_ptr<const UdpMessage>;
135 
139 using UdpMessagePtr = std::unique_ptr<UdpMessage>;
140 
141 } // namespace udp
142 } // namespace socket
143 } // namespace boost_support
144 #endif // DIAG_CLIENT_LIB_LIB_BOOST_SUPPORT_SOCKET_UDP_UDP_MESSAGE_H_
Immutable class to store received udp message.
Definition: udp_message.h:31
std::vector< uint8_t > BufferType
Type alias for underlying buffer.
Definition: udp_message.h:36
BufferType tx_buffer_
The transmission buffer.
Definition: udp_message.h:118
BufferType rx_buffer_
The reception buffer.
Definition: udp_message.h:113
std::uint16_t host_port_number_
Store remote port number.
Definition: udp_message.h:128
std::uint16_t GetHostPortNumber() const
Get the host port number.
Definition: udp_message.h:89
IpAddressType GetHostIpAddress() const
Get the host ip address.
Definition: udp_message.h:83
UdpMessage & operator=(const UdpMessage &other)=delete
IpAddressType host_ip_address_
Store remote ip address.
Definition: udp_message.h:123
UdpMessage(IpAddressType host_ip_address, std::uint16_t host_port_number, BufferType payload)
Constructs an instance of UdpMessage.
Definition: udp_message.h:62
UdpMessage(const UdpMessage &other)=delete
core_type::Span< std::uint8_t > GetRxBuffer()
Get the view to the rx buffer.
Definition: udp_message.h:95
std::string_view IpAddressType
Type alias of IP address type.
Definition: udp_message.h:41
virtual ~UdpMessage()=default
Destructs an instance of UdpMessage.
BufferType & GetTxBuffer()
Get the reference to tx buffer.
Definition: udp_message.h:101
UdpMessage(UdpMessage &&other) noexcept=default
UdpMessage & operator=(UdpMessage &&other) noexcept=default
BufferType const & GetTxBuffer() const
Get the reference to tx buffer.
Definition: udp_message.h:107
UdpMessage(IpAddressType host_ip_address, std::uint16_t host_port_number)
Default constructor of UdpMessage.
Definition: udp_message.h:47
std::unique_ptr< const UdpMessage > UdpMessageConstPtr
The unique pointer to const UdpMessage.
Definition: udp_message.h:134
constexpr std::uint8_t kDoipUdpResSize
Doip maximum response size.
Definition: udp_message.h:26
std::unique_ptr< UdpMessage > UdpMessagePtr
The unique pointer to UdpMessage.
Definition: udp_message.h:139