- P& succeed(U&& value) {
- result = std::forward(value);
- return *static_cast(this);
- }
+// An OBIS ID like: "1-0:1.7.0.255"
+struct ObisId final {
+ std::array v{};
+ constexpr explicit ObisId(const uint8_t a, const uint8_t b = 255, const uint8_t c = 255, const uint8_t d = 255, const uint8_t e = 255,
+ const uint8_t f = 255) noexcept
+ : v{a, b, c, d, e, f} {};
+ ObisId() = default;
+ bool operator==(const ObisId&) const = default;
};
-// partial specialization for void result
-template
-struct _ParseResult {};
-
-// Actual ParseResult class
-template
-struct ParseResult final : public _ParseResult, T> {
- const char* next = nullptr;
- const char* err = nullptr;
- const char* ctx = nullptr;
+// Represents an unencrypted DSMR telegram that starts with '/' and ends with '!' without CRC at the end.
+// Example:
+// "/AAA5MTR\r\n"
+// "\r\n"
+// "1-0:1.7.0(00.100*kW)\r\n"
+// "1-0:1.7.0(00.200*kW)\r\n"
+// "!";
+class DsmrUnencryptedTelegram final {
+ std::string_view data;
+public:
+ explicit DsmrUnencryptedTelegram(std::string_view telegram) : data(telegram) {}
+ std::string_view content() const { return data; }
+};
- ParseResult& fail(const char* error, const char* context = nullptr) noexcept {
- this->err = error;
- this->ctx = context;
- return *this;
- }
+enum class LogLevel {
+ VERY_VERBOSE,
+ VERBOSE,
+ DEBUG,
+ INFO,
+ WARNING,
+ ERROR,
+};
- ParseResult& until(const char* nextToken) noexcept {
- this->next = nextToken;
- return *this;
+class Logger final {
+public:
+ static void set_log_function(std::function func) { _log_function = std::move(func); }
+
+#if defined(_MSC_VER)
+ static void log(LogLevel log_level, _In_z_ _Printf_format_string_ const char* fmt, ...) {
+#elif defined(__clang__) || defined(__GNUC__)
+ __attribute__((format(printf, 2, 3)))
+ static void log(LogLevel log_level, const char* fmt, ...) {
+#else
+ static void log(LogLevel log_level, const char* fmt, ...) {
+#endif
+ va_list args;
+ va_start(args, fmt);
+ _log_function(log_level, fmt, args);
+ va_end(args);
}
- ParseResult() = default;
+private:
+ Logger() = default;
- template
- ParseResult(const ParseResult