ESPHome 2026.9.0-dev
Loading...
Searching...
No Matches
api_buffer.cpp
Go to the documentation of this file.
1#include "api_buffer.h"
2#include <new>
3
4namespace esphome::api {
5
6bool APIBuffer::grow_(size_t n) {
7 // nothrow (no zero-fill) so OOM is reportable; plain new aborts instead
8 // (NEW_OOM_ABORT on ESP8266 Arduino, exception stub on ESP-IDF).
9 // RAMAllocator is no fit here: unique_ptr needs delete[]-compatible memory.
10 std::unique_ptr<uint8_t[]> new_data(new (std::nothrow) uint8_t[n]);
11 if (new_data == nullptr)
12 return false;
13 if (this->size_)
14 std::memcpy(new_data.get(), this->data_.get(), this->size_);
15 this->data_ = std::move(new_data);
16 this->capacity_ = n;
17 return true;
18}
19
20} // namespace esphome::api
bool grow_(size_t n)
Definition api_buffer.cpp:6
std::unique_ptr< uint8_t[]> data_
Definition api_buffer.h:58
auto * new_data
Definition helpers.cpp:29