Woman, Life, Freedom


DoIP Library
Diagnostics over Internet Protocol (DoIP) C++ library
message.h
1#ifndef MESSAGE_H
2#define MESSAGE_H
3
4#include <vector>
5#include "./payload_type.h"
6#include "./generic_nack_type.h"
7
8namespace DoipLib
9{
11 class Message
12 {
13 private:
14 uint8_t mProtocolVersion;
15 const PayloadType mPayloadType;
16
17 protected:
19 static const std::size_t cHeaderSize{8};
20
23 explicit Message(PayloadType payloadType) noexcept;
24
28 Message(uint8_t protocolVersion, PayloadType payloadType) noexcept;
29
32 virtual void GetPayload(std::vector<uint8_t> &payload) const = 0;
33
38 virtual bool TrySetPayload(
39 const std::vector<uint8_t> &payload,
40 uint32_t payloadLength) = 0;
41
42 public:
45 void Serialize(std::vector<uint8_t> &serializedMessage) const;
46
52 const std::vector<uint8_t> &serializedMessage,
53 GenericNackType &nackCode);
54
60 const std::vector<uint8_t> &serializedMessage,
61 PayloadType &payloadType);
62
63 virtual ~Message() noexcept = default;
64 };
65}
66
67#endif
DoIP generic message.
Definition: message.h:12
Message(PayloadType payloadType) noexcept
Constructor.
void Serialize(std::vector< uint8_t > &serializedMessage) const
Serialize DoIP message.
Message(uint8_t protocolVersion, PayloadType payloadType) noexcept
Constructor.
virtual void GetPayload(std::vector< uint8_t > &payload) const =0
Get message payload.
bool TryDeserialize(const std::vector< uint8_t > &serializedMessage, GenericNackType &nackCode)
Try to deserialize DoIP message.
static const std::size_t cHeaderSize
DoIP message header size.
Definition: message.h:19
static bool TryExtractPayloadType(const std::vector< uint8_t > &serializedMessage, PayloadType &payloadType)
Try to extract the payload type from the given serialized message.
virtual bool TrySetPayload(const std::vector< uint8_t > &payload, uint32_t payloadLength)=0
Try to set message payload.