|
ESPHome 2026.3.0
|
Byte buffer that skips zero-initialization on resize(). More...
#include <api_buffer.h>
Public Member Functions | |
| void | clear () |
| void | reserve (size_t n) ESPHOME_ALWAYS_INLINE |
| void | resize (size_t n) ESPHOME_ALWAYS_INLINE |
| uint8_t * | data () |
| const uint8_t * | data () const |
| size_t | size () 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 | |
| void | 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 36 of file api_buffer.h.
|
inline |
Definition at line 38 of file api_buffer.h.
|
inline |
Definition at line 47 of file api_buffer.h.
|
inline |
Definition at line 48 of file api_buffer.h.
|
inline |
Definition at line 50 of file api_buffer.h.
|
protected |
Definition at line 5 of file api_buffer.cpp.
|
inline |
Definition at line 51 of file api_buffer.h.
|
inline |
Definition at line 52 of file api_buffer.h.
|
inline |
Release all memory (equivalent to std::vector swap trick).
Definition at line 54 of file api_buffer.h.
|
inline |
Definition at line 39 of file api_buffer.h.
|
inline |
Definition at line 43 of file api_buffer.h.
|
inline |
Definition at line 49 of file api_buffer.h.
|
protected |
Definition at line 64 of file api_buffer.h.
|
protected |
Definition at line 62 of file api_buffer.h.
|
protected |
Definition at line 63 of file api_buffer.h.