nmealib 0.0.4
NMEA 0183/NMEA 2000 parsing library
Loading...
Searching...
No Matches
message.h
Go to the documentation of this file.
1#pragma once
2
3#include <string>
4#include <chrono>
5#include <memory>
6
7namespace nmealib {
8
14class Message {
15public:
20 enum class Type { Unknown, NMEA0183, NMEA2000 };
21
28 static std::string typeToString(Type t);
29
30 using TimePoint = std::chrono::system_clock::time_point;
31
33 explicit Message(std::string raw,
34 Type type = Type::Unknown,
35 TimePoint ts = std::chrono::system_clock::now()) noexcept;
36
37 virtual ~Message();
38
39 Message(const Message&) = default;
40 Message& operator=(const Message&) = default;
41 Message(Message&&) noexcept = default;
42 Message& operator=(Message&&) noexcept = default;
43
49 Type getType() const noexcept;
50
56 const std::string& getRawData() const noexcept;
57
63 TimePoint getTimestamp() const noexcept;
64
70 virtual std::unique_ptr<Message> clone() const = 0;
71
77 virtual std::string serialize() const = 0;
78
85 virtual bool validate() const = 0;
86
94 bool operator==(const Message& other) const noexcept;
95
96protected:
97 std::string rawData_;
100
106 void setType(Type t) noexcept;
107
113 void setRaw(std::string r) noexcept;
114
120 void setTimestamp(TimePoint ts) noexcept;
121};
122
123} // namespace nmealib
Defines a base class for NMEA messages, encapsulating common properties and behaviors.
Definition message.h:14
void setType(Type t) noexcept
Sets the message type.
Definition message.cpp:38
void setRaw(std::string r) noexcept
Sets the raw data string.
Definition message.cpp:42
std::string rawData_
Definition message.h:97
std::chrono::system_clock::time_point TimePoint
Definition message.h:30
const std::string & getRawData() const noexcept
Returns the raw, unmodified data string as received.
Definition message.cpp:25
virtual std::string serialize() const =0
Produces the wire-format representation of this message.
Type getType() const noexcept
Returns the message type.
Definition message.cpp:21
Type
Defines the type of NMEA message, allowing for differentiation between various standards.
Definition message.h:20
void setTimestamp(TimePoint ts) noexcept
Sets the message timestamp.
Definition message.cpp:46
virtual std::unique_ptr< Message > clone() const =0
Creates a polymorphic deep copy of this message.
virtual bool validate() const =0
Validates the message contents (e.g., checksum, length).
TimePoint getTimestamp() const noexcept
Returns the timestamp associated with this message.
Definition message.cpp:29
static std::string typeToString(Type t)
Converts a Message::Type enum value to its string representation.
Definition message.cpp:5
TimePoint timestamp_
Definition message.h:99