Diag-Client-Lib
doip_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 DIAGNOSTIC_CLIENT_LIB_LIB_DOIP_CLIENT_COMMON_DOIP_MESSAGE_H
9 #define DIAGNOSTIC_CLIENT_LIB_LIB_DOIP_CLIENT_COMMON_DOIP_MESSAGE_H
10 
11 #include <cstdint>
12 #include <string>
13 #include <string_view>
14 
15 #include "core/include/span.h"
16 
17 namespace doip_client {
21 class DoipMessage final {
22  public:
26  enum class MessageType : std::uint8_t { kUdp, kTcp };
27 
31  enum class RxSocketType : std::uint8_t { kBroadcast, kUnicast };
32 
36  using IpAddressType = std::string_view;
37 
38  public:
50  DoipMessage(MessageType message_type, IpAddressType host_ip_address, std::uint16_t host_port_number,
52 
56  DoipMessage(const DoipMessage &other) = default;
57  DoipMessage(DoipMessage &&other) noexcept = default;
58  DoipMessage &operator=(const DoipMessage &other) = default;
59  DoipMessage &operator=(DoipMessage &&other) noexcept = default;
60 
64  ~DoipMessage() noexcept = default;
65 
71 
76  std::uint16_t GetHostPortNumber() const { return host_port_number_; }
77 
82  std::uint8_t GetProtocolVersion() const { return protocol_version_; }
83 
88  std::uint8_t GetInverseProtocolVersion() const { return protocol_version_inv_; }
89 
94  std::uint16_t GetPayloadType() const { return payload_type_; }
95 
100  std::uint16_t GetServerAddress() const { return server_address_; }
101 
106  std::uint16_t GetClientAddress() const { return client_address_; }
107 
112  std::uint32_t GetPayloadLength() const { return payload_length_; }
113 
119 
120  private:
128  std::string host_ip_address_;
129 
133  std::uint16_t host_port_number_;
134 
138  std::uint8_t protocol_version_;
139 
143  std::uint8_t protocol_version_inv_;
144 
148  std::uint16_t server_address_;
149 
153  std::uint16_t client_address_;
154 
158  std::uint16_t payload_type_;
159 
163  std::uint32_t payload_length_;
164 
169 };
170 } // namespace doip_client
171 
172 #endif //DIAGNOSTIC_CLIENT_LIB_LIB_DOIP_CLIENT_COMMON_DOIP_MESSAGE_H
Immutable class to store received doip message.
Definition: doip_message.h:21
MessageType message_type_
Store the message type.
Definition: doip_message.h:124
DoipMessage(MessageType message_type, IpAddressType host_ip_address, std::uint16_t host_port_number, core_type::Span< std::uint8_t > payload)
Constructs an instance of DoipMessage.
std::uint8_t GetInverseProtocolVersion() const
Get the inverse protocol version.
Definition: doip_message.h:88
std::uint16_t GetServerAddress() const
Get the payload type.
Definition: doip_message.h:100
DoipMessage(DoipMessage &&other) noexcept=default
~DoipMessage() noexcept=default
Destructs an instance of DoipMessage.
std::uint16_t client_address_
Store server address.
Definition: doip_message.h:153
std::uint8_t protocol_version_
Store protocol version.
Definition: doip_message.h:138
std::uint16_t GetPayloadType() const
Get the payload type.
Definition: doip_message.h:94
core_type::Span< std::uint8_t > GetPayload() const
Get the payload.
Definition: doip_message.h:118
DoipMessage & operator=(DoipMessage &&other) noexcept=default
std::uint8_t protocol_version_inv_
Store protocol inverse version.
Definition: doip_message.h:143
MessageType
Definition of message type.
Definition: doip_message.h:26
std::uint16_t GetClientAddress() const
Get the payload type.
Definition: doip_message.h:106
std::uint16_t server_address_
Store server address.
Definition: doip_message.h:148
std::uint32_t payload_length_
Store payload length.
Definition: doip_message.h:163
RxSocketType
Definition of socket type from where the request was received.
Definition: doip_message.h:31
std::uint16_t GetHostPortNumber() const
Get the host port number.
Definition: doip_message.h:76
DoipMessage & operator=(const DoipMessage &other)=default
core_type::Span< std::uint8_t > payload_
Store payload.
Definition: doip_message.h:168
std::uint32_t GetPayloadLength() const
Get the payload length.
Definition: doip_message.h:112
DoipMessage(const DoipMessage &other)=default
Default copy assignment, copy constructor, move assignment and move constructor.
std::string host_ip_address_
Store remote ip address.
Definition: doip_message.h:128
std::uint16_t host_port_number_
Store remote port number.
Definition: doip_message.h:133
std::uint16_t payload_type_
Store payload type.
Definition: doip_message.h:158
IpAddressType GetHostIpAddress() const
Get the host ip address.
Definition: doip_message.h:70
std::uint8_t GetProtocolVersion() const
Get the protocol version.
Definition: doip_message.h:82
std::string_view IpAddressType
Type alias of IP address type.
Definition: doip_message.h:36