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

#include <proto.h>

Public Member Functions

 ProtoWriteBuffer (APIBuffer *buffer)
 
 ProtoWriteBuffer (APIBuffer *buffer, size_t write_pos)
 
void ESPHOME_ALWAYS_INLINE encode_varint_raw (uint32_t value)
 
void encode_field_raw (uint32_t field_id, uint32_t type)
 Encode a field key (tag/wire type combination).
 
template<typename T >
void encode_sub_message (uint32_t field_id, const T &value)
 Single-pass encode for repeated submessage elements.
 
template<typename T >
void encode_optional_sub_message (uint32_t field_id, const T &value)
 Encode an optional singular submessage field — skips if empty.
 
void encode_sub_message (uint32_t field_id, const void *value, uint8_t *(*encode_fn)(const void *, ProtoWriteBuffer &PROTO_ENCODE_DEBUG_PARAM))
 
void encode_optional_sub_message (uint32_t field_id, uint32_t nested_size, const void *value, uint8_t *(*encode_fn)(const void *, ProtoWriteBuffer &PROTO_ENCODE_DEBUG_PARAM))
 
APIBufferget_buffer () const
 
uint8_t * get_pos () const
 
void set_pos (uint8_t *pos)
 

Protected Member Functions

void encode_varint_raw_slow_ (uint32_t value) __attribute__((noinline))
 
void debug_check_bounds_ (size_t bytes, const char *caller=__builtin_FUNCTION())
 
void debug_check_encode_size_ (uint32_t field_id, uint32_t expected, ptrdiff_t actual)
 
void debug_check_bounds_ (size_t bytes)
 

Protected Attributes

APIBufferbuffer_
 
uint8_t * pos_
 

Detailed Description

Definition at line 231 of file proto.h.

Constructor & Destructor Documentation

◆ ProtoWriteBuffer() [1/2]

esphome::api::ProtoWriteBuffer::ProtoWriteBuffer ( APIBuffer * buffer)
inline

Definition at line 233 of file proto.h.

◆ ProtoWriteBuffer() [2/2]

esphome::api::ProtoWriteBuffer::ProtoWriteBuffer ( APIBuffer * buffer,
size_t write_pos )
inline

Definition at line 234 of file proto.h.

Member Function Documentation

◆ debug_check_bounds_() [1/2]

void esphome::api::ProtoWriteBuffer::debug_check_bounds_ ( size_t bytes)
inlineprotected

Definition at line 283 of file proto.h.

◆ debug_check_bounds_() [2/2]

void esphome::api::ProtoWriteBuffer::debug_check_bounds_ ( size_t bytes,
const char * caller = __builtin_FUNCTION() )
protected

Definition at line 198 of file proto.cpp.

◆ debug_check_encode_size_()

void esphome::api::ProtoWriteBuffer::debug_check_encode_size_ ( uint32_t field_id,
uint32_t expected,
ptrdiff_t actual )
protected

Definition at line 205 of file proto.cpp.

◆ encode_field_raw()

void esphome::api::ProtoWriteBuffer::encode_field_raw ( uint32_t field_id,
uint32_t type )
inline

Encode a field key (tag/wire type combination).

Parameters
field_idField number (tag) in the protobuf message
typeWire type value:
  • 0: Varint (int32, int64, uint32, uint64, sint32, sint64, bool, enum)
  • 2: Length-delimited (string, bytes, embedded messages, packed repeated fields)
  • 5: 32-bit (fixed32, sfixed32, float)
  • Note: Wire type 1 (64-bit fixed) is not supported

Following https://protobuf.dev/programming-guides/encoding/#structure

Definition at line 255 of file proto.h.

◆ encode_optional_sub_message() [1/2]

template<typename T >
void esphome::api::ProtoWriteBuffer::encode_optional_sub_message ( uint32_t field_id,
const T & value )
inline

Encode an optional singular submessage field — skips if empty.

Thin template wrapper; all buffer work is in the non-template core.

Definition at line 860 of file proto.h.

◆ encode_optional_sub_message() [2/2]

void esphome::api::ProtoWriteBuffer::encode_optional_sub_message ( uint32_t field_id,
uint32_t nested_size,
const void * value,
uint8_t *(* encode_fn )(const void *, ProtoWriteBuffer &PROTO_ENCODE_DEBUG_PARAM) )

Definition at line 176 of file proto.cpp.

◆ encode_sub_message() [1/2]

template<typename T >
void esphome::api::ProtoWriteBuffer::encode_sub_message ( uint32_t field_id,
const T & value )
inline

Single-pass encode for repeated submessage elements.

Thin template wrapper; all buffer work is in the non-template core.

Definition at line 855 of file proto.h.

◆ encode_sub_message() [2/2]

void esphome::api::ProtoWriteBuffer::encode_sub_message ( uint32_t field_id,
const void * value,
uint8_t *(* encode_fn )(const void *, ProtoWriteBuffer &PROTO_ENCODE_DEBUG_PARAM) )

Definition at line 147 of file proto.cpp.

◆ encode_varint_raw()

void ESPHOME_ALWAYS_INLINE esphome::api::ProtoWriteBuffer::encode_varint_raw ( uint32_t value)
inline

Definition at line 235 of file proto.h.

◆ encode_varint_raw_slow_()

void esphome::api::ProtoWriteBuffer::encode_varint_raw_slow_ ( uint32_t value)
protected

Definition at line 13 of file proto.cpp.

◆ get_buffer()

APIBuffer * esphome::api::ProtoWriteBuffer::get_buffer ( ) const
inline

Definition at line 271 of file proto.h.

◆ get_pos()

uint8_t * esphome::api::ProtoWriteBuffer::get_pos ( ) const
inline

Definition at line 272 of file proto.h.

◆ set_pos()

void esphome::api::ProtoWriteBuffer::set_pos ( uint8_t * pos)
inline

Definition at line 273 of file proto.h.

Field Documentation

◆ buffer_

APIBuffer* esphome::api::ProtoWriteBuffer::buffer_
protected

Definition at line 286 of file proto.h.

◆ pos_

uint8_t* esphome::api::ProtoWriteBuffer::pos_
protected

Definition at line 287 of file proto.h.


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