From 789611a611eecb33e4f3c848fbd3e02a353911bd Mon Sep 17 00:00:00 2001 From: Tomer27cz Date: Sat, 7 Mar 2026 20:39:57 +0100 Subject: [PATCH] Make DLMS string helpers write to buffer Change DlmsParser::data_to_string_ and obis_to_string_ signatures to return void and write into the provided caller buffer instead of returning std::string (avoids allocations and clarifies ownership). Also add #include "esphome/core/application.h" in dlms_push.cpp for required declarations. --- components/dlms_push/dlms_parser.h | 4 ++-- components/dlms_push/dlms_push.cpp | 1 + 2 files changed, 3 insertions(+), 2 deletions(-) diff --git a/components/dlms_push/dlms_parser.h b/components/dlms_push/dlms_parser.h index f185ea9..1acf5a4 100644 --- a/components/dlms_push/dlms_parser.h +++ b/components/dlms_push/dlms_parser.h @@ -113,8 +113,8 @@ class DlmsParser { void emit_object_(const AxdrDescriptorPattern &pat, const AxdrCaptures &c); float data_as_float_(DlmsDataType value_type, const uint8_t *ptr, uint8_t len); - std::string data_to_string_(DlmsDataType value_type, const uint8_t *ptr, uint8_t len, char *buffer, size_t max_len); - std::string obis_to_string_(const uint8_t *obis, char *buffer, size_t max_len); + void data_to_string_(DlmsDataType value_type, const uint8_t *ptr, uint8_t len, char *buffer, size_t max_len); + void obis_to_string_(const uint8_t *obis, char *buffer, size_t max_len); const char *dlms_data_type_to_string_(DlmsDataType vt); const uint8_t *buffer_{nullptr}; diff --git a/components/dlms_push/dlms_push.cpp b/components/dlms_push/dlms_push.cpp index 5744528..6118c08 100644 --- a/components/dlms_push/dlms_push.cpp +++ b/components/dlms_push/dlms_push.cpp @@ -2,6 +2,7 @@ #include "dlms_parser.h" #include "esphome/core/log.h" +#include "esphome/core/application.h" #include "esphome/core/helpers.h" namespace esphome {