Diag-Client-Lib
All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Macros Pages
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,
51  std::uint16_t host_port_number, core_type::Span<std::uint8_t const> payload);
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:
124  std::string host_ip_address_;
125 
129  std::uint16_t host_port_number_;
130 
134  std::uint8_t protocol_version_;
135 
139  std::uint8_t protocol_version_inv_;
140 
144  std::uint16_t server_address_;
145 
149  std::uint16_t client_address_;
150 
154  std::uint16_t payload_type_;
155 
159  std::uint32_t payload_length_;
160 
165 };
166 } // namespace doip_client
167 
168 #endif //DIAGNOSTIC_CLIENT_LIB_LIB_DOIP_CLIENT_COMMON_DOIP_MESSAGE_H
A view over a contiguous sequence of objects.
Definition: span.h:191
Immutable class to store received doip message.
Definition: doip_message.h:21
DoipMessage(MessageType message_type, IpAddressType host_ip_address, std::uint16_t host_port_number, core_type::Span< std::uint8_t const > 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:149
core_type::Span< std::uint8_t const > GetPayload() const
Get the payload.
Definition: doip_message.h:118
std::uint8_t protocol_version_
Store protocol version.
Definition: doip_message.h:134
std::uint16_t GetPayloadType() const
Get the payload type.
Definition: doip_message.h:94
DoipMessage & operator=(DoipMessage &&other) noexcept=default
core_type::Span< std::uint8_t const > payload_
Store payload.
Definition: doip_message.h:164
std::uint8_t protocol_version_inv_
Store protocol inverse version.
Definition: doip_message.h:139
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:144
std::uint32_t payload_length_
Store payload length.
Definition: doip_message.h:159
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
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:124
std::uint16_t host_port_number_
Store remote port number.
Definition: doip_message.h:129
std::uint16_t payload_type_
Store payload type.
Definition: doip_message.h:154
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