ESPHome 2025.12.0-dev
Loading...
Searching...
No Matches
split_buffer.h
Go to the documentation of this file.
1#pragma once
2
3#include <cstdint>
4#include <cstdlib>
5
6namespace esphome::split_buffer {
15 public:
16 SplitBuffer() = default;
18
19 // Initialize the buffer with the desired total length
20 bool init(size_t total_length);
21
22 // Free all allocated buffers
23 void free();
24
25 // Access operators
26 uint8_t &operator[](size_t index);
27 const uint8_t &operator[](size_t index) const;
28 void fill(uint8_t value) const;
29
30 // Get the total length
31 size_t size() const { return this->total_length_; }
32
33 // Get buffer information
34 size_t get_buffer_count() const { return this->buffer_count_; }
35
36 // Check if successfully initialized
37 bool is_valid() const { return this->buffers_ != nullptr && this->buffer_count_ > 0; }
38
39 private:
40 uint8_t **buffers_{nullptr};
41 size_t buffer_count_{0};
42 size_t buffer_size_{0};
43 size_t total_length_{0};
44};
45
46} // namespace esphome::split_buffer
A SplitBuffer allocates a large memory buffer potentially as multiple smaller buffers to facilitate a...
void fill(uint8_t value) const
Fill the entire buffer with a single byte value.
uint8_t & operator[](size_t index)
void init()
Definition core.cpp:109