ESPHome 2025.5.0
|
#include <api_pb2_size.h>
Static Public Member Functions | |
static uint32_t | varint (uint32_t value) |
ProtoSize class for Protocol Buffer serialization size calculation. | |
static uint32_t | varint (uint64_t value) |
Calculates the size in bytes needed to encode a uint64_t value as a varint. | |
static uint32_t | varint (int32_t value) |
Calculates the size in bytes needed to encode an int32_t value as a varint. | |
static uint32_t | varint (int64_t value) |
Calculates the size in bytes needed to encode an int64_t value as a varint. | |
static 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 void | add_int32_field (uint32_t &total_size, uint32_t field_id_size, int32_t value, bool force=false) |
Common parameters for all add_*_field methods. | |
static void | add_uint32_field (uint32_t &total_size, uint32_t field_id_size, uint32_t value, bool force=false) |
Calculates and adds the size of a uint32 field to the total message size. | |
static void | add_bool_field (uint32_t &total_size, uint32_t field_id_size, bool value, bool force=false) |
Calculates and adds the size of a boolean field to the total message size. | |
template<uint32_t NumBytes> | |
static void | add_fixed_field (uint32_t &total_size, uint32_t field_id_size, bool is_nonzero, bool force=false) |
Calculates and adds the size of a fixed field to the total message size. | |
static void | add_enum_field (uint32_t &total_size, uint32_t field_id_size, uint32_t value, bool force=false) |
Calculates and adds the size of an enum field to the total message size. | |
static void | add_sint32_field (uint32_t &total_size, uint32_t field_id_size, int32_t value, bool force=false) |
Calculates and adds the size of a sint32 field to the total message size. | |
static void | add_int64_field (uint32_t &total_size, uint32_t field_id_size, int64_t value, bool force=false) |
Calculates and adds the size of an int64 field to the total message size. | |
static void | add_uint64_field (uint32_t &total_size, uint32_t field_id_size, uint64_t value, bool force=false) |
Calculates and adds the size of a uint64 field to the total message size. | |
static void | add_sint64_field (uint32_t &total_size, uint32_t field_id_size, int64_t value, bool force=false) |
Calculates and adds the size of a sint64 field to the total message size. | |
static void | add_string_field (uint32_t &total_size, uint32_t field_id_size, const std::string &str, bool force=false) |
Calculates and adds the size of a string/bytes field to the total message size. | |
static void | add_message_field (uint32_t &total_size, uint32_t field_id_size, uint32_t nested_size, bool force=false) |
Calculates and adds the size of a nested message field to the total message size. | |
template<typename MessageType > | |
static void | add_message_object (uint32_t &total_size, uint32_t field_id_size, const MessageType &message, bool force=false) |
Calculates and adds the size of a nested message field to the total message size. | |
template<typename MessageType > | |
static void | add_repeated_message (uint32_t &total_size, uint32_t field_id_size, const std::vector< MessageType > &messages) |
Calculates and adds the sizes of all messages in a repeated field to the total message size. | |
Definition at line 10 of file api_pb2_size.h.
|
inlinestatic |
Calculates and adds the size of a boolean field to the total message size.
Definition at line 177 of file api_pb2_size.h.
|
inlinestatic |
Calculates and adds the size of an enum field to the total message size.
Enum fields are encoded as uint32 varints.
Definition at line 212 of file api_pb2_size.h.
|
inlinestatic |
Calculates and adds the size of a fixed field to the total message size.
Fixed fields always take exactly N bytes (4 for fixed32/float, 8 for fixed64/double).
NumBytes | The number of bytes for this fixed field (4 or 8) |
is_nonzero | Whether the value is non-zero |
Definition at line 196 of file api_pb2_size.h.
|
inlinestatic |
Common parameters for all add_*_field methods.
All add_*_field methods follow these common patterns:
total_size | Reference to the total message size to update |
field_id_size | Pre-calculated size of the field ID in bytes |
value | The value to calculate size for (type varies) |
force | Whether to calculate size even if the value is default/zero/empty |
Each method follows this implementation pattern:
Calculates and adds the size of an int32 field to the total message size
Definition at line 144 of file api_pb2_size.h.
|
inlinestatic |
Calculates and adds the size of an int64 field to the total message size.
Definition at line 241 of file api_pb2_size.h.
|
inlinestatic |
Calculates and adds the size of a nested message field to the total message size.
This helper function directly updates the total_size reference if the nested size is greater than zero or force is true.
nested_size | The pre-calculated size of the nested message |
Definition at line 304 of file api_pb2_size.h.
|
inlinestatic |
Calculates and adds the size of a nested message field to the total message size.
This templated version directly takes a message object, calculates its size internally, and updates the total_size reference. This eliminates the need for a temporary variable at the call site.
MessageType | The type of the nested message (inferred from parameter) |
message | The nested message object |
Definition at line 327 of file api_pb2_size.h.
|
inlinestatic |
Calculates and adds the sizes of all messages in a repeated field to the total message size.
This helper processes a vector of message objects, calculating the size for each message and adding it to the total size.
MessageType | The type of the nested messages in the vector |
messages | Vector of message objects |
Definition at line 346 of file api_pb2_size.h.
|
inlinestatic |
Calculates and adds the size of a sint32 field to the total message size.
Sint32 fields use ZigZag encoding, which is more efficient for negative values.
Definition at line 227 of file api_pb2_size.h.
|
inlinestatic |
Calculates and adds the size of a sint64 field to the total message size.
Sint64 fields use ZigZag encoding, which is more efficient for negative values.
Definition at line 270 of file api_pb2_size.h.
|
inlinestatic |
Calculates and adds the size of a string/bytes field to the total message size.
Definition at line 284 of file api_pb2_size.h.
|
inlinestatic |
Calculates and adds the size of a uint32 field to the total message size.
Definition at line 163 of file api_pb2_size.h.
|
inlinestatic |
Calculates and adds the size of a uint64 field to the total message size.
Definition at line 254 of file api_pb2_size.h.
|
inlinestatic |
Calculates the size in bytes needed to encode a field ID and wire type.
field_id | The field identifier |
type | The wire type value (from the WireType enum in the protobuf spec) |
Definition at line 120 of file api_pb2_size.h.
|
inlinestatic |
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.
value | The int32_t value to calculate size for |
Definition at line 90 of file api_pb2_size.h.
|
inlinestatic |
Calculates the size in bytes needed to encode an int64_t value as a varint.
value | The int64_t value to calculate size for |
Definition at line 106 of file api_pb2_size.h.
|
inlinestatic |
ProtoSize class for Protocol Buffer serialization size calculation.
This class provides static methods to calculate the exact byte counts needed for encoding various Protocol Buffer field types. All methods are designed to be efficient for the common case where many fields have default values.
Implements Protocol Buffer encoding size calculation according to: https://protobuf.dev/programming-guides/encoding/
Key features:
Calculates the size in bytes needed to encode a uint32_t value as a varint
value | The uint32_t value to calculate size for |
Definition at line 35 of file api_pb2_size.h.
|
inlinestatic |
Calculates the size in bytes needed to encode a uint64_t value as a varint.
value | The uint64_t value to calculate size for |
Definition at line 59 of file api_pb2_size.h.