include proper header for allocator and mark the functions as override

This commit is contained in:
Kevin Ahrendt 2025-05-20 14:46:54 +00:00
parent ef072eb655
commit d97f473e4a

View File

@ -1,6 +1,8 @@
#include "json_util.h" #include "json_util.h"
#include "esphome/core/log.h" #include "esphome/core/log.h"
#include <ArduinoJson/Memory/Allocator.hpp>
namespace esphome { namespace esphome {
namespace json { namespace json {
@ -11,13 +13,15 @@ static auto ALLOCATOR = RAMAllocator<uint8_t>(
// Build an allocator for the JSON Library using the RAMAllocator class // Build an allocator for the JSON Library using the RAMAllocator class
struct SpiRamAllocator : ArduinoJson::Allocator { struct SpiRamAllocator : ArduinoJson::Allocator {
void *allocate(size_t size) { return ALLOCATOR.allocate(size); } void *allocate(size_t size) override { return ALLOCATOR.allocate(size); }
void deallocate(void *pointer) { void deallocate(void *pointer) override {
free(pointer); // NOLINT(cppcoreguidelines-owning-memory,cppcoreguidelines-no-malloc) free(pointer); // NOLINT(cppcoreguidelines-owning-memory,cppcoreguidelines-no-malloc)
} }
void *reallocate(void *ptr, size_t new_size) { return ALLOCATOR.reallocate(static_cast<uint8_t *>(ptr), new_size); } void *reallocate(void *ptr, size_t new_size) override {
return ALLOCATOR.reallocate(static_cast<uint8_t *>(ptr), new_size);
}
}; };
static auto DOC_ALLOCATOR = SpiRamAllocator(); static auto DOC_ALLOCATOR = SpiRamAllocator();