|
ESPHome 2026.9.0-dev
|
Byte buffer that skips zero-initialization on resize(). More...
#include <api_buffer.h>
Public Member Functions | |
| void | clear () |
| bool | reserve (size_t n) ESPHOME_ALWAYS_INLINE |
| Returns false if allocation fails; the buffer is left unchanged. | |
| bool | resize (size_t n) ESPHOME_ALWAYS_INLINE |
| Returns false if allocation fails; the buffer is left unchanged. No zero-fill. | |
| bool | reserve_and_resize (size_t reserve_size, size_t new_size) ESPHOME_ALWAYS_INLINE |
| Reserve capacity for max(reserve_size, new_size) bytes, then set size to new_size. | |
| uint8_t * | data () |
| const uint8_t * | data () const |
| size_t | size () const |
| size_t | capacity () const |
| bool | empty () const |
| uint8_t & | operator[] (size_t i) |
| const uint8_t & | operator[] (size_t i) const |
| void | release () |
| Release all memory (equivalent to std::vector swap trick). | |
Protected Member Functions | |
| bool | grow_ (size_t n) |
Protected Attributes | |
| std::unique_ptr< uint8_t[]> | data_ |
| size_t | size_ {0} |
| size_t | capacity_ {0} |
Byte buffer that skips zero-initialization on resize().
std::vector<uint8_t>::resize() zero-fills new bytes via memset. For the shared protobuf write buffer, every byte is overwritten by the encoder, making the zero-fill pure waste. For the receive buffer, bytes are overwritten by socket reads.
Designed for bulk clear/resize/overwrite patterns. grow_() allocates exactly the requested size (no growth factor) since callers resize to known sizes rather than appending incrementally.
Safe because: callers always write exactly the number of bytes they resize for. In the protobuf write path, debug_check_bounds_ validates writes in debug builds.
Definition at line 26 of file api_buffer.h.
|
inline |
Definition at line 45 of file api_buffer.h.
|
inline |
Definition at line 28 of file api_buffer.h.
|
inline |
Definition at line 42 of file api_buffer.h.
|
inline |
Definition at line 43 of file api_buffer.h.
|
inline |
Definition at line 46 of file api_buffer.h.
|
protected |
Definition at line 6 of file api_buffer.cpp.
|
inline |
Definition at line 47 of file api_buffer.h.
|
inline |
Definition at line 48 of file api_buffer.h.
|
inline |
Release all memory (equivalent to std::vector swap trick).
Definition at line 50 of file api_buffer.h.
|
inlinenodiscard |
Returns false if allocation fails; the buffer is left unchanged.
Definition at line 30 of file api_buffer.h.
|
inlinenodiscard |
Reserve capacity for max(reserve_size, new_size) bytes, then set size to new_size.
Single grow_ check regardless of argument order. Returns false if allocation fails; the buffer is left unchanged.
Definition at line 36 of file api_buffer.h.
|
inlinenodiscard |
Returns false if allocation fails; the buffer is left unchanged. No zero-fill.
Definition at line 32 of file api_buffer.h.
|
inline |
Definition at line 44 of file api_buffer.h.
|
protected |
Definition at line 60 of file api_buffer.h.
|
protected |
Definition at line 58 of file api_buffer.h.
|
protected |
Definition at line 59 of file api_buffer.h.