ESPHome 2026.10.2
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 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 775 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 916 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 917 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 921 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 965 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 918 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 904 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 907 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 933 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 936 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 953 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 956 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 971 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 974 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 924 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 968 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 927 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 930 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 959 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 962 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 910 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 913 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 939 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 949 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 942 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 897 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 867 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 883 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 796 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 836 of file proto.h.

◆ varint16()

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

Definition at line 786 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 805 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 779 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 780 of file proto.h.

◆ VARINT_THRESHOLD_3_BYTE

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

Definition at line 781 of file proto.h.

◆ VARINT_THRESHOLD_4_BYTE

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

Definition at line 782 of file proto.h.


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