ESPHome 2026.5.0-dev
Loading...
Searching...
No Matches
esphome::api::ProtoEncode Class Reference

Static encode helpers for generated encode() functions. More...

#include <proto.h>

Static Public Member Functions

template<typename T >
static void encode_varint_raw_loop (uint8_t *__restrict__ &pos PROTO_ENCODE_DEBUG_PARAM, T value)
 Write a multi-byte varint directly through a pos pointer.
 
static void ESPHOME_ALWAYS_INLINE encode_varint_raw (uint8_t *__restrict__ &pos PROTO_ENCODE_DEBUG_PARAM, uint32_t value)
 
static void ESPHOME_ALWAYS_INLINE encode_varint_raw_short (uint8_t *__restrict__ &pos PROTO_ENCODE_DEBUG_PARAM, uint32_t value)
 Encode a varint that is expected to be 1-2 bytes (e.g. zigzag RSSI, small lengths).
 
static void ESPHOME_ALWAYS_INLINE encode_varint_raw_64 (uint8_t *__restrict__ &pos PROTO_ENCODE_DEBUG_PARAM, uint64_t value)
 
static void ESPHOME_ALWAYS_INLINE encode_field_raw (uint8_t *__restrict__ &pos PROTO_ENCODE_DEBUG_PARAM, uint32_t field_id, uint32_t type)
 
static void ESPHOME_ALWAYS_INLINE write_raw_byte (uint8_t *__restrict__ &pos PROTO_ENCODE_DEBUG_PARAM, uint8_t b)
 Write a single precomputed tag byte. Tag must be < 128.
 
static void ESPHOME_ALWAYS_INLINE reserve_byte (uint8_t *__restrict__ &pos PROTO_ENCODE_DEBUG_PARAM)
 Reserve one byte for later backpatch (e.g., sub-message length).
 
static void ESPHOME_ALWAYS_INLINE encode_raw (uint8_t *__restrict__ &pos PROTO_ENCODE_DEBUG_PARAM, const void *data, size_t len)
 Write raw bytes to the buffer (no tag, no length prefix).
 
static void encode_short_string_force (uint8_t *__restrict__ &pos PROTO_ENCODE_DEBUG_PARAM, uint8_t tag, const StringRef &ref)
 Encode tag + 1-byte length + raw string data.
 
static void ESPHOME_ALWAYS_INLINE write_tag_and_fixed32 (uint8_t *__restrict__ &pos PROTO_ENCODE_DEBUG_PARAM, uint8_t tag, uint32_t value)
 Write a precomputed tag byte + 32-bit value in one operation.
 
static void encode_string (uint8_t *__restrict__ &pos PROTO_ENCODE_DEBUG_PARAM, uint32_t field_id, const char *string, size_t len, bool force=false)
 
static void encode_string (uint8_t *__restrict__ &pos PROTO_ENCODE_DEBUG_PARAM, uint32_t field_id, const std::string &value, bool force=false)
 
static void encode_string (uint8_t *__restrict__ &pos PROTO_ENCODE_DEBUG_PARAM, uint32_t field_id, const StringRef &ref, bool force=false)
 
static void encode_bytes (uint8_t *__restrict__ &pos PROTO_ENCODE_DEBUG_PARAM, uint32_t field_id, const uint8_t *data, size_t len, bool force=false)
 
static void encode_uint32 (uint8_t *__restrict__ &pos PROTO_ENCODE_DEBUG_PARAM, uint32_t field_id, uint32_t value, bool force=false)
 
static void encode_uint64 (uint8_t *__restrict__ &pos PROTO_ENCODE_DEBUG_PARAM, uint32_t field_id, uint64_t value, bool force=false)
 
static void encode_bool (uint8_t *__restrict__ &pos PROTO_ENCODE_DEBUG_PARAM, uint32_t field_id, bool value, bool force=false)
 
static void encode_fixed32 (uint8_t *__restrict__ &pos PROTO_ENCODE_DEBUG_PARAM, uint32_t field_id, uint32_t value, bool force=false)
 
static void encode_float (uint8_t *__restrict__ &pos PROTO_ENCODE_DEBUG_PARAM, uint32_t field_id, float value, bool force=false)
 
static void encode_int32 (uint8_t *__restrict__ &pos PROTO_ENCODE_DEBUG_PARAM, uint32_t field_id, int32_t value, bool force=false)
 
static void encode_int64 (uint8_t *__restrict__ &pos PROTO_ENCODE_DEBUG_PARAM, uint32_t field_id, int64_t value, bool force=false)
 
static void encode_sint32 (uint8_t *__restrict__ &pos PROTO_ENCODE_DEBUG_PARAM, uint32_t field_id, int32_t value, bool force=false)
 
static void encode_sint64 (uint8_t *__restrict__ &pos PROTO_ENCODE_DEBUG_PARAM, uint32_t field_id, int64_t value, bool force=false)
 
template<typename T >
static void encode_sub_message (uint8_t *__restrict__ &pos PROTO_ENCODE_DEBUG_PARAM, ProtoWriteBuffer &buffer, uint32_t field_id, const T &value)
 Sub-message encoding: sync pos to buffer, delegate, get pos from return value.
 
template<typename T >
static void encode_optional_sub_message (uint8_t *__restrict__ &pos PROTO_ENCODE_DEBUG_PARAM, ProtoWriteBuffer &buffer, uint32_t field_id, const T &value)
 

Detailed Description

Static encode helpers for generated encode() functions.

Generated code hoists buffer.pos_ into a local uint8_t *__restrict__ pos, then calls these methods which take pos by reference. No struct, no overhead. For sub-messages, pos is synced back to buffer before the call and reloaded after.

Definition at line 298 of file proto.h.

Member Function Documentation

◆ encode_bool()

static void esphome::api::ProtoEncode::encode_bool ( uint8_t *__restrict__ &pos PROTO_ENCODE_DEBUG_PARAM,
uint32_t field_id,
bool value,
bool force = false )
inlinestatic

Definition at line 437 of file proto.h.

◆ encode_bytes()

static void esphome::api::ProtoEncode::encode_bytes ( uint8_t *__restrict__ &pos PROTO_ENCODE_DEBUG_PARAM,
uint32_t field_id,
const uint8_t * data,
size_t len,
bool force = false )
inlinestatic

Definition at line 419 of file proto.h.

◆ encode_field_raw()

static void ESPHOME_ALWAYS_INLINE esphome::api::ProtoEncode::encode_field_raw ( uint8_t *__restrict__ &pos PROTO_ENCODE_DEBUG_PARAM,
uint32_t field_id,
uint32_t type )
inlinestatic

Definition at line 345 of file proto.h.

◆ encode_fixed32()

static void esphome::api::ProtoEncode::encode_fixed32 ( uint8_t *__restrict__ &pos PROTO_ENCODE_DEBUG_PARAM,
uint32_t field_id,
uint32_t value,
bool force = false )
inlinestatic

Definition at line 445 of file proto.h.

◆ encode_float()

static void esphome::api::ProtoEncode::encode_float ( uint8_t *__restrict__ &pos PROTO_ENCODE_DEBUG_PARAM,
uint32_t field_id,
float value,
bool force = false )
inlinestatic

Definition at line 465 of file proto.h.

◆ encode_int32()

static void esphome::api::ProtoEncode::encode_int32 ( uint8_t *__restrict__ &pos PROTO_ENCODE_DEBUG_PARAM,
uint32_t field_id,
int32_t value,
bool force = false )
inlinestatic

Definition at line 472 of file proto.h.

◆ encode_int64()

static void esphome::api::ProtoEncode::encode_int64 ( uint8_t *__restrict__ &pos PROTO_ENCODE_DEBUG_PARAM,
uint32_t field_id,
int64_t value,
bool force = false )
inlinestatic

Definition at line 481 of file proto.h.

◆ encode_optional_sub_message()

template<typename T >
static void esphome::api::ProtoEncode::encode_optional_sub_message ( uint8_t *__restrict__ &pos PROTO_ENCODE_DEBUG_PARAM,
ProtoWriteBuffer & buffer,
uint32_t field_id,
const T & value )
inlinestatic

Definition at line 502 of file proto.h.

◆ encode_raw()

static void ESPHOME_ALWAYS_INLINE esphome::api::ProtoEncode::encode_raw ( uint8_t *__restrict__ &pos PROTO_ENCODE_DEBUG_PARAM,
const void * data,
size_t len )
inlinestatic

Write raw bytes to the buffer (no tag, no length prefix).

Definition at line 362 of file proto.h.

◆ encode_short_string_force()

static void esphome::api::ProtoEncode::encode_short_string_force ( uint8_t *__restrict__ &pos PROTO_ENCODE_DEBUG_PARAM,
uint8_t tag,
const StringRef & ref )
inlinestatic

Encode tag + 1-byte length + raw string data.

For strings with max_data_length < 128. Tag must be a single-byte varint (< 128). Always encodes (no zero check).

Definition at line 370 of file proto.h.

◆ encode_sint32()

static void esphome::api::ProtoEncode::encode_sint32 ( uint8_t *__restrict__ &pos PROTO_ENCODE_DEBUG_PARAM,
uint32_t field_id,
int32_t value,
bool force = false )
inlinestatic

Definition at line 485 of file proto.h.

◆ encode_sint64()

static void esphome::api::ProtoEncode::encode_sint64 ( uint8_t *__restrict__ &pos PROTO_ENCODE_DEBUG_PARAM,
uint32_t field_id,
int64_t value,
bool force = false )
inlinestatic

Definition at line 489 of file proto.h.

◆ encode_string() [1/3]

static void esphome::api::ProtoEncode::encode_string ( uint8_t *__restrict__ &pos PROTO_ENCODE_DEBUG_PARAM,
uint32_t field_id,
const char * string,
size_t len,
bool force = false )
inlinestatic

Definition at line 396 of file proto.h.

◆ encode_string() [2/3]

static void esphome::api::ProtoEncode::encode_string ( uint8_t *__restrict__ &pos PROTO_ENCODE_DEBUG_PARAM,
uint32_t field_id,
const std::string & value,
bool force = false )
inlinestatic

Definition at line 411 of file proto.h.

◆ encode_string() [3/3]

static void esphome::api::ProtoEncode::encode_string ( uint8_t *__restrict__ &pos PROTO_ENCODE_DEBUG_PARAM,
uint32_t field_id,
const StringRef & ref,
bool force = false )
inlinestatic

Definition at line 415 of file proto.h.

◆ encode_sub_message()

template<typename T >
static void esphome::api::ProtoEncode::encode_sub_message ( uint8_t *__restrict__ &pos PROTO_ENCODE_DEBUG_PARAM,
ProtoWriteBuffer & buffer,
uint32_t field_id,
const T & value )
inlinestatic

Sub-message encoding: sync pos to buffer, delegate, get pos from return value.

Definition at line 495 of file proto.h.

◆ encode_uint32()

static void esphome::api::ProtoEncode::encode_uint32 ( uint8_t *__restrict__ &pos PROTO_ENCODE_DEBUG_PARAM,
uint32_t field_id,
uint32_t value,
bool force = false )
inlinestatic

Definition at line 423 of file proto.h.

◆ encode_uint64()

static void esphome::api::ProtoEncode::encode_uint64 ( uint8_t *__restrict__ &pos PROTO_ENCODE_DEBUG_PARAM,
uint32_t field_id,
uint64_t value,
bool force = false )
inlinestatic

Definition at line 430 of file proto.h.

◆ encode_varint_raw()

static void ESPHOME_ALWAYS_INLINE esphome::api::ProtoEncode::encode_varint_raw ( uint8_t *__restrict__ &pos PROTO_ENCODE_DEBUG_PARAM,
uint32_t value )
inlinestatic

Definition at line 311 of file proto.h.

◆ encode_varint_raw_64()

static void ESPHOME_ALWAYS_INLINE esphome::api::ProtoEncode::encode_varint_raw_64 ( uint8_t *__restrict__ &pos PROTO_ENCODE_DEBUG_PARAM,
uint64_t value )
inlinestatic

Definition at line 336 of file proto.h.

◆ encode_varint_raw_loop()

template<typename T >
static void esphome::api::ProtoEncode::encode_varint_raw_loop ( uint8_t *__restrict__ &pos PROTO_ENCODE_DEBUG_PARAM,
T value )
inlinestatic

Write a multi-byte varint directly through a pos pointer.

Definition at line 302 of file proto.h.

◆ encode_varint_raw_short()

static void ESPHOME_ALWAYS_INLINE esphome::api::ProtoEncode::encode_varint_raw_short ( uint8_t *__restrict__ &pos PROTO_ENCODE_DEBUG_PARAM,
uint32_t value )
inlinestatic

Encode a varint that is expected to be 1-2 bytes (e.g. zigzag RSSI, small lengths).

Definition at line 321 of file proto.h.

◆ reserve_byte()

static void ESPHOME_ALWAYS_INLINE esphome::api::ProtoEncode::reserve_byte ( uint8_t *__restrict__ &pos PROTO_ENCODE_DEBUG_PARAM)
inlinestatic

Reserve one byte for later backpatch (e.g., sub-message length).

Advances pos past the reserved byte without writing a value.

Definition at line 357 of file proto.h.

◆ write_raw_byte()

static void ESPHOME_ALWAYS_INLINE esphome::api::ProtoEncode::write_raw_byte ( uint8_t *__restrict__ &pos PROTO_ENCODE_DEBUG_PARAM,
uint8_t b )
inlinestatic

Write a single precomputed tag byte. Tag must be < 128.

Definition at line 350 of file proto.h.

◆ write_tag_and_fixed32()

static void ESPHOME_ALWAYS_INLINE esphome::api::ProtoEncode::write_tag_and_fixed32 ( uint8_t *__restrict__ &pos PROTO_ENCODE_DEBUG_PARAM,
uint8_t tag,
uint32_t value )
inlinestatic

Write a precomputed tag byte + 32-bit value in one operation.

Definition at line 382 of file proto.h.


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