ESPHome 2026.6.0-dev
Loading...
Searching...
No Matches
esphome::api::ProtoSize Class Reference

#include <proto.h>

Static Public Member Functions

static constexpr uint8_t ESPHOME_ALWAYS_INLINE varint16 (uint16_t value)
 
static constexpr uint8_t ESPHOME_ALWAYS_INLINE varint8 (uint8_t value)
 
static constexpr uint32_t ESPHOME_ALWAYS_INLINE varint (uint32_t value)
 Calculates the size in bytes needed to encode a uint32_t value as a varint.
 
static constexpr uint32_t ESPHOME_ALWAYS_INLINE varint_short (uint32_t value)
 Size of a varint expected to be 1-2 bytes (e.g.
 
static constexpr uint32_t varint (uint64_t value)
 Calculates the size in bytes needed to encode a uint64_t value as a varint.
 
static constexpr uint32_t varint (int32_t value)
 Calculates the size in bytes needed to encode an int32_t value as a varint.
 
static constexpr uint32_t varint (int64_t value)
 Calculates the size in bytes needed to encode an int64_t value as a varint.
 
static constexpr uint32_t field (uint32_t field_id, uint32_t type)
 Calculates the size in bytes needed to encode a field ID and wire type.
 
static constexpr uint32_t calc_int32 (uint32_t field_id_size, int32_t value)
 
static constexpr uint32_t calc_int32_force (uint32_t field_id_size, int32_t value)
 
static constexpr uint32_t calc_uint32 (uint32_t field_id_size, uint32_t value)
 
static constexpr uint32_t calc_uint32_force (uint32_t field_id_size, uint32_t value)
 
static constexpr uint32_t calc_bool (uint32_t field_id_size, bool value)
 
static constexpr uint32_t calc_bool_force (uint32_t field_id_size)
 
static uint32_t calc_float (uint32_t field_id_size, float value)
 
static constexpr uint32_t calc_fixed32 (uint32_t field_id_size, uint32_t value)
 
static constexpr uint32_t calc_sfixed32 (uint32_t field_id_size, int32_t value)
 
static constexpr uint32_t calc_sint32 (uint32_t field_id_size, int32_t value)
 
static constexpr uint32_t ESPHOME_ALWAYS_INLINE calc_sint32_force (uint32_t field_id_size, int32_t value)
 
static constexpr uint32_t calc_int64 (uint32_t field_id_size, int64_t value)
 
static constexpr uint32_t calc_int64_force (uint32_t field_id_size, int64_t value)
 
static constexpr uint32_t calc_uint64 (uint32_t field_id_size, uint64_t value)
 
static constexpr uint32_t ESPHOME_ALWAYS_INLINE calc_uint64_force (uint32_t field_id_size, uint64_t value)
 
static constexpr uint32_t ESPHOME_ALWAYS_INLINE calc_uint64_48bit_force (uint32_t field_id_size, uint64_t value)
 48-bit MAC address variant: matches encode_varint_raw_48bit's fast path.
 
static constexpr uint32_t calc_length (uint32_t field_id_size, size_t len)
 
static constexpr uint32_t ESPHOME_ALWAYS_INLINE calc_length_force (uint32_t field_id_size, size_t len)
 
static constexpr uint32_t calc_sint64 (uint32_t field_id_size, int64_t value)
 
static constexpr uint32_t calc_sint64_force (uint32_t field_id_size, int64_t value)
 
static constexpr uint32_t calc_fixed64 (uint32_t field_id_size, uint64_t value)
 
static constexpr uint32_t calc_sfixed64 (uint32_t field_id_size, int64_t value)
 
static constexpr uint32_t calc_message (uint32_t field_id_size, uint32_t nested_size)
 
static constexpr uint32_t ESPHOME_ALWAYS_INLINE calc_message_force (uint32_t field_id_size, uint32_t nested_size)
 

Static Public Attributes

static constexpr uint32_t VARINT_THRESHOLD_1_BYTE = VARINT_MAX_1_BYTE
 
static constexpr uint32_t VARINT_THRESHOLD_2_BYTE = VARINT_MAX_2_BYTE
 
static constexpr uint32_t VARINT_THRESHOLD_3_BYTE = 1 << 21
 
static constexpr uint32_t VARINT_THRESHOLD_4_BYTE = 1 << 28
 

Detailed Description

Definition at line 672 of file proto.h.

Member Function Documentation

◆ calc_bool()

static constexpr uint32_t esphome::api::ProtoSize::calc_bool ( uint32_t field_id_size,
bool value )
inlinestaticconstexpr

Definition at line 818 of file proto.h.

◆ calc_bool_force()

static constexpr uint32_t esphome::api::ProtoSize::calc_bool_force ( uint32_t field_id_size)
inlinestaticconstexpr

Definition at line 819 of file proto.h.

◆ calc_fixed32()

static constexpr uint32_t esphome::api::ProtoSize::calc_fixed32 ( uint32_t field_id_size,
uint32_t value )
inlinestaticconstexpr

Definition at line 823 of file proto.h.

◆ calc_fixed64()

static constexpr uint32_t esphome::api::ProtoSize::calc_fixed64 ( uint32_t field_id_size,
uint64_t value )
inlinestaticconstexpr

Definition at line 867 of file proto.h.

◆ calc_float()

static uint32_t esphome::api::ProtoSize::calc_float ( uint32_t field_id_size,
float value )
inlinestatic

Definition at line 820 of file proto.h.

◆ calc_int32()

static constexpr uint32_t esphome::api::ProtoSize::calc_int32 ( uint32_t field_id_size,
int32_t value )
inlinestaticconstexpr

Definition at line 806 of file proto.h.

◆ calc_int32_force()

static constexpr uint32_t esphome::api::ProtoSize::calc_int32_force ( uint32_t field_id_size,
int32_t value )
inlinestaticconstexpr

Definition at line 809 of file proto.h.

◆ calc_int64()

static constexpr uint32_t esphome::api::ProtoSize::calc_int64 ( uint32_t field_id_size,
int64_t value )
inlinestaticconstexpr

Definition at line 835 of file proto.h.

◆ calc_int64_force()

static constexpr uint32_t esphome::api::ProtoSize::calc_int64_force ( uint32_t field_id_size,
int64_t value )
inlinestaticconstexpr

Definition at line 838 of file proto.h.

◆ calc_length()

static constexpr uint32_t esphome::api::ProtoSize::calc_length ( uint32_t field_id_size,
size_t len )
inlinestaticconstexpr

Definition at line 855 of file proto.h.

◆ calc_length_force()

static constexpr uint32_t ESPHOME_ALWAYS_INLINE esphome::api::ProtoSize::calc_length_force ( uint32_t field_id_size,
size_t len )
inlinestaticconstexpr

Definition at line 858 of file proto.h.

◆ calc_message()

static constexpr uint32_t esphome::api::ProtoSize::calc_message ( uint32_t field_id_size,
uint32_t nested_size )
inlinestaticconstexpr

Definition at line 873 of file proto.h.

◆ calc_message_force()

static constexpr uint32_t ESPHOME_ALWAYS_INLINE esphome::api::ProtoSize::calc_message_force ( uint32_t field_id_size,
uint32_t nested_size )
inlinestaticconstexpr

Definition at line 876 of file proto.h.

◆ calc_sfixed32()

static constexpr uint32_t esphome::api::ProtoSize::calc_sfixed32 ( uint32_t field_id_size,
int32_t value )
inlinestaticconstexpr

Definition at line 826 of file proto.h.

◆ calc_sfixed64()

static constexpr uint32_t esphome::api::ProtoSize::calc_sfixed64 ( uint32_t field_id_size,
int64_t value )
inlinestaticconstexpr

Definition at line 870 of file proto.h.

◆ calc_sint32()

static constexpr uint32_t esphome::api::ProtoSize::calc_sint32 ( uint32_t field_id_size,
int32_t value )
inlinestaticconstexpr

Definition at line 829 of file proto.h.

◆ calc_sint32_force()

static constexpr uint32_t ESPHOME_ALWAYS_INLINE esphome::api::ProtoSize::calc_sint32_force ( uint32_t field_id_size,
int32_t value )
inlinestaticconstexpr

Definition at line 832 of file proto.h.

◆ calc_sint64()

static constexpr uint32_t esphome::api::ProtoSize::calc_sint64 ( uint32_t field_id_size,
int64_t value )
inlinestaticconstexpr

Definition at line 861 of file proto.h.

◆ calc_sint64_force()

static constexpr uint32_t esphome::api::ProtoSize::calc_sint64_force ( uint32_t field_id_size,
int64_t value )
inlinestaticconstexpr

Definition at line 864 of file proto.h.

◆ calc_uint32()

static constexpr uint32_t esphome::api::ProtoSize::calc_uint32 ( uint32_t field_id_size,
uint32_t value )
inlinestaticconstexpr

Definition at line 812 of file proto.h.

◆ calc_uint32_force()

static constexpr uint32_t esphome::api::ProtoSize::calc_uint32_force ( uint32_t field_id_size,
uint32_t value )
inlinestaticconstexpr

Definition at line 815 of file proto.h.

◆ calc_uint64()

static constexpr uint32_t esphome::api::ProtoSize::calc_uint64 ( uint32_t field_id_size,
uint64_t value )
inlinestaticconstexpr

Definition at line 841 of file proto.h.

◆ calc_uint64_48bit_force()

static constexpr uint32_t ESPHOME_ALWAYS_INLINE esphome::api::ProtoSize::calc_uint64_48bit_force ( uint32_t field_id_size,
uint64_t value )
inlinestaticconstexpr

48-bit MAC address variant: matches encode_varint_raw_48bit's fast path.

When any of the top 6 of 48 bits is set the encoded varint is 7 bytes; otherwise fall back to the general size calculation. Caller must guarantee value fits in 48 bits (encoder asserts in debug).

Definition at line 851 of file proto.h.

◆ calc_uint64_force()

static constexpr uint32_t ESPHOME_ALWAYS_INLINE esphome::api::ProtoSize::calc_uint64_force ( uint32_t field_id_size,
uint64_t value )
inlinestaticconstexpr

Definition at line 844 of file proto.h.

◆ field()

static constexpr uint32_t esphome::api::ProtoSize::field ( uint32_t field_id,
uint32_t type )
inlinestaticconstexpr

Calculates the size in bytes needed to encode a field ID and wire type.

Parameters
field_idThe field identifier
typeThe wire type value (from the WireType enum in the protobuf spec)
Returns
The number of bytes needed to encode the field ID and wire type

Definition at line 799 of file proto.h.

◆ varint() [1/4]

static constexpr uint32_t esphome::api::ProtoSize::varint ( int32_t value)
inlinestaticconstexpr

Calculates the size in bytes needed to encode an int32_t value as a varint.

Special handling is needed for negative values, which are sign-extended to 64 bits in Protocol Buffers, resulting in a 10-byte varint.

Parameters
valueThe int32_t value to calculate size for
Returns
The number of bytes needed to encode the value

Definition at line 769 of file proto.h.

◆ varint() [2/4]

static constexpr uint32_t esphome::api::ProtoSize::varint ( int64_t value)
inlinestaticconstexpr

Calculates the size in bytes needed to encode an int64_t value as a varint.

Parameters
valueThe int64_t value to calculate size for
Returns
The number of bytes needed to encode the value

Definition at line 785 of file proto.h.

◆ varint() [3/4]

static constexpr uint32_t ESPHOME_ALWAYS_INLINE esphome::api::ProtoSize::varint ( uint32_t value)
inlinestaticconstexpr

Calculates the size in bytes needed to encode a uint32_t value as a varint.

Parameters
valueThe uint32_t value to calculate size for
Returns
The number of bytes needed to encode the value

Definition at line 698 of file proto.h.

◆ varint() [4/4]

static constexpr uint32_t esphome::api::ProtoSize::varint ( uint64_t value)
inlinestaticconstexpr

Calculates the size in bytes needed to encode a uint64_t value as a varint.

Parameters
valueThe uint64_t value to calculate size for
Returns
The number of bytes needed to encode the value

Definition at line 738 of file proto.h.

◆ varint16()

static constexpr uint8_t ESPHOME_ALWAYS_INLINE esphome::api::ProtoSize::varint16 ( uint16_t value)
inlinestaticconstexpr

Definition at line 683 of file proto.h.

◆ varint8()

static constexpr uint8_t ESPHOME_ALWAYS_INLINE esphome::api::ProtoSize::varint8 ( uint8_t value)
inlinestaticconstexpr

Definition at line 688 of file proto.h.

◆ varint_short()

static constexpr uint32_t ESPHOME_ALWAYS_INLINE esphome::api::ProtoSize::varint_short ( uint32_t value)
inlinestaticconstexpr

Size of a varint expected to be 1-2 bytes (e.g.

zigzag RSSI, small lengths). Inlines both checks; falls back to slow path for 3+ bytes.

Definition at line 707 of file proto.h.

Field Documentation

◆ VARINT_THRESHOLD_1_BYTE

uint32_t esphome::api::ProtoSize::VARINT_THRESHOLD_1_BYTE = VARINT_MAX_1_BYTE
staticconstexpr

Definition at line 676 of file proto.h.

◆ VARINT_THRESHOLD_2_BYTE

uint32_t esphome::api::ProtoSize::VARINT_THRESHOLD_2_BYTE = VARINT_MAX_2_BYTE
staticconstexpr

Definition at line 677 of file proto.h.

◆ VARINT_THRESHOLD_3_BYTE

uint32_t esphome::api::ProtoSize::VARINT_THRESHOLD_3_BYTE = 1 << 21
staticconstexpr

Definition at line 678 of file proto.h.

◆ VARINT_THRESHOLD_4_BYTE

uint32_t esphome::api::ProtoSize::VARINT_THRESHOLD_4_BYTE = 1 << 28
staticconstexpr

Definition at line 679 of file proto.h.


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