ESPHome 2026.11.0-dev
Loading...
Searching...
No Matches
esphome::TemplatableBytes< Ts > Class Template Reference

Byte payload that is either a stateless lambda or a static table, which may be in PROGMEM. More...

#include <automation.h>

Public Member Functions

void set_template (std::vector< uint8_t >(*func)(Ts...))
 
void set_static (const uint8_t *data, uint16_t len)
 
bool is_static () const
 
const uint8_t * data () const
 Only valid when is_static(); may point to PROGMEM, so read it with progmem_memcpy or progmem_read_byte.
 
size_t size () const
 Only valid when is_static().
 
std::vector< uint8_t > value (const Ts &...x) const
 
template<size_t N = 64, typename F >
void visit (F &&fn, const Ts &...x) const
 Calls fn(const uint8_t *data, size_t len) with the payload readable from RAM: a lambda's vector, a static table directly, or on ESP8266 a copy of the PROGMEM table (on the stack up to N bytes).
 

Static Protected Member Functions

static std::vector< uint8_t > to_vector (const uint8_t *data, size_t len)
 

Protected Attributes

union { 
 
   std::vector< uint8_t >(*   func )(Ts...) 
 
   const uint8_t *   data 
 
} code_ 
 
int32_t len_ {-1}
 

Detailed Description

template<typename... Ts>
class esphome::TemplatableBytes< Ts >

Byte payload that is either a stateless lambda or a static table, which may be in PROGMEM.

8 bytes on 32-bit; codegen stores constant payloads as shared flash tables.

Definition at line 84 of file automation.h.

Member Function Documentation

◆ data()

template<typename... Ts>
const uint8_t * esphome::TemplatableBytes< Ts >::data ( ) const
inline

Only valid when is_static(); may point to PROGMEM, so read it with progmem_memcpy or progmem_read_byte.

Definition at line 96 of file automation.h.

◆ is_static()

template<typename... Ts>
bool esphome::TemplatableBytes< Ts >::is_static ( ) const
inline

Definition at line 94 of file automation.h.

◆ set_static()

template<typename... Ts>
void esphome::TemplatableBytes< Ts >::set_static ( const uint8_t * data,
uint16_t len )
inline

Definition at line 90 of file automation.h.

◆ set_template()

template<typename... Ts>
void esphome::TemplatableBytes< Ts >::set_template ( std::vector< uint8_t >(* func )(Ts...))
inline

Definition at line 86 of file automation.h.

◆ size()

template<typename... Ts>
size_t esphome::TemplatableBytes< Ts >::size ( ) const
inline

Only valid when is_static().

Definition at line 98 of file automation.h.

◆ to_vector()

template<typename... Ts>
static std::vector< uint8_t > esphome::TemplatableBytes< Ts >::to_vector ( const uint8_t * data,
size_t len )
inlinestaticprotected

Definition at line 123 of file automation.h.

◆ value()

template<typename... Ts>
std::vector< uint8_t > esphome::TemplatableBytes< Ts >::value ( const Ts &... x) const
inline

Definition at line 99 of file automation.h.

◆ visit()

template<typename... Ts>
template<size_t N = 64, typename F >
void esphome::TemplatableBytes< Ts >::visit ( F && fn,
const Ts &... x ) const
inline

Calls fn(const uint8_t *data, size_t len) with the payload readable from RAM: a lambda's vector, a static table directly, or on ESP8266 a copy of the PROGMEM table (on the stack up to N bytes).

Definition at line 106 of file automation.h.

Field Documentation

◆ [union]

union { ... } esphome::TemplatableBytes< Ts >::code_

◆ data

template<typename... Ts>
const uint8_t* esphome::TemplatableBytes< Ts >::data

Definition at line 133 of file automation.h.

◆ func

template<typename... Ts>
std::vector< uint8_t >(* esphome::TemplatableBytes< Ts >::func) (Ts...)

Definition at line 135 of file automation.h.

◆ len_

template<typename... Ts>
int32_t esphome::TemplatableBytes< Ts >::len_ {-1}
protected

Definition at line 135 of file automation.h.


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