ESPHome 2026.3.0-dev
Loading...
Searching...
No Matches
esphome::json::SerializationBuffer< STACK_SIZE > Class Template Reference

Buffer for JSON serialization that uses stack allocation for small payloads. More...

#include <json_util.h>

Public Member Functions

 SerializationBuffer (size_t size)
 Construct with known size (typically from measureJson)
 
 ~SerializationBuffer ()
 
 SerializationBuffer (SerializationBuffer &&other) noexcept
 
SerializationBufferoperator= (SerializationBuffer &&other) noexcept
 
 SerializationBuffer (const SerializationBuffer &)=delete
 
SerializationBufferoperator= (const SerializationBuffer &)=delete
 
const char * c_str () const
 Get null-terminated C string.
 
const char * data () const
 Get data pointer.
 
size_t size () const
 Get string length (excluding null terminator)
 
 operator std::string () const
 Implicit conversion to std::string for backward compatibility WARNING: This allocates a new std::string on the heap.
 

Static Public Attributes

static constexpr size_t BUFFER_SIZE = STACK_SIZE
 Stack buffer size for this instantiation.
 

Detailed Description

template<size_t STACK_SIZE = 640>
class esphome::json::SerializationBuffer< STACK_SIZE >

Buffer for JSON serialization that uses stack allocation for small payloads.

Template parameter STACK_SIZE specifies the stack buffer size (default 512 bytes). Supports move semantics for efficient return-by-value.

Definition at line 22 of file json_util.h.

Constructor & Destructor Documentation

◆ SerializationBuffer() [1/3]

template<size_t STACK_SIZE = 640>
esphome::json::SerializationBuffer< STACK_SIZE >::SerializationBuffer ( size_t size)
inlineexplicit

Construct with known size (typically from measureJson)

Definition at line 27 of file json_util.h.

◆ ~SerializationBuffer()

template<size_t STACK_SIZE = 640>
esphome::json::SerializationBuffer< STACK_SIZE >::~SerializationBuffer ( )
inline

Definition at line 37 of file json_util.h.

◆ SerializationBuffer() [2/3]

template<size_t STACK_SIZE = 640>
esphome::json::SerializationBuffer< STACK_SIZE >::SerializationBuffer ( SerializationBuffer< STACK_SIZE > && other)
inlinenoexcept

Definition at line 40 of file json_util.h.

◆ SerializationBuffer() [3/3]

template<size_t STACK_SIZE = 640>
esphome::json::SerializationBuffer< STACK_SIZE >::SerializationBuffer ( const SerializationBuffer< STACK_SIZE > & )
delete

Member Function Documentation

◆ c_str()

template<size_t STACK_SIZE = 640>
const char * esphome::json::SerializationBuffer< STACK_SIZE >::c_str ( ) const
inline

Get null-terminated C string.

Definition at line 82 of file json_util.h.

◆ data()

template<size_t STACK_SIZE = 640>
const char * esphome::json::SerializationBuffer< STACK_SIZE >::data ( ) const
inline

Get data pointer.

Definition at line 84 of file json_util.h.

◆ operator std::string()

template<size_t STACK_SIZE = 640>
esphome::json::SerializationBuffer< STACK_SIZE >::operator std::string ( ) const
inline

Implicit conversion to std::string for backward compatibility WARNING: This allocates a new std::string on the heap.

Prefer using c_str() or data()/size() directly when possible to avoid allocation.

Definition at line 91 of file json_util.h.

◆ operator=() [1/2]

template<size_t STACK_SIZE = 640>
SerializationBuffer & esphome::json::SerializationBuffer< STACK_SIZE >::operator= ( const SerializationBuffer< STACK_SIZE > & )
delete

◆ operator=() [2/2]

template<size_t STACK_SIZE = 640>
SerializationBuffer & esphome::json::SerializationBuffer< STACK_SIZE >::operator= ( SerializationBuffer< STACK_SIZE > && other)
inlinenoexcept

Definition at line 57 of file json_util.h.

◆ size()

template<size_t STACK_SIZE = 640>
size_t esphome::json::SerializationBuffer< STACK_SIZE >::size ( ) const
inline

Get string length (excluding null terminator)

Definition at line 86 of file json_util.h.

Field Documentation

◆ BUFFER_SIZE

template<size_t STACK_SIZE = 640>
size_t esphome::json::SerializationBuffer< STACK_SIZE >::BUFFER_SIZE = STACK_SIZE
staticconstexpr

Stack buffer size for this instantiation.

Definition at line 24 of file json_util.h.


The documentation for this class was generated from the following file: