diff --git a/esphome/components/api/api_pb2.cpp b/esphome/components/api/api_pb2.cpp index e2d1cfebd4..9e061d2cf0 100644 --- a/esphome/components/api/api_pb2.cpp +++ b/esphome/components/api/api_pb2.cpp @@ -36,11 +36,11 @@ void HelloResponse::encode(ProtoWriteBuffer buffer) const { buffer.encode_string(3, this->server_info_ref_); buffer.encode_string(4, this->name_ref_); } -void HelloResponse::calculate_size(uint32_t &total_size) const { - ProtoSize::add_uint32_field(total_size, 1, this->api_version_major); - ProtoSize::add_uint32_field(total_size, 1, this->api_version_minor); - ProtoSize::add_string_field(total_size, 1, this->server_info_ref_.size()); - ProtoSize::add_string_field(total_size, 1, this->name_ref_.size()); +void HelloResponse::calculate_size(ProtoSize &size) const { + size.add_uint32_field(1, this->api_version_major); + size.add_uint32_field(1, this->api_version_minor); + size.add_string_field(1, this->server_info_ref_.size()); + size.add_string_field(1, this->name_ref_.size()); } bool ConnectRequest::decode_length(uint32_t field_id, ProtoLengthDelimited value) { switch (field_id) { @@ -53,17 +53,17 @@ bool ConnectRequest::decode_length(uint32_t field_id, ProtoLengthDelimited value return true; } void ConnectResponse::encode(ProtoWriteBuffer buffer) const { buffer.encode_bool(1, this->invalid_password); } -void ConnectResponse::calculate_size(uint32_t &total_size) const { - ProtoSize::add_bool_field(total_size, 1, this->invalid_password); +} +void ConnectResponse::calculate_size(ProtoSize &size) const { size.add_bool_field(1, this->invalid_password); } } #ifdef USE_AREAS void AreaInfo::encode(ProtoWriteBuffer buffer) const { buffer.encode_uint32(1, this->area_id); buffer.encode_string(2, this->name_ref_); } -void AreaInfo::calculate_size(uint32_t &total_size) const { - ProtoSize::add_uint32_field(total_size, 1, this->area_id); - ProtoSize::add_string_field(total_size, 1, this->name_ref_.size()); +void AreaInfo::calculate_size(ProtoSize &size) const { + size.add_uint32_field(1, this->area_id); + size.add_string_field(1, this->name_ref_.size()); } #endif #ifdef USE_DEVICES @@ -72,10 +72,10 @@ void DeviceInfo::encode(ProtoWriteBuffer buffer) const { buffer.encode_string(2, this->name_ref_); buffer.encode_uint32(3, this->area_id); } -void DeviceInfo::calculate_size(uint32_t &total_size) const { - ProtoSize::add_uint32_field(total_size, 1, this->device_id); - ProtoSize::add_string_field(total_size, 1, this->name_ref_.size()); - ProtoSize::add_uint32_field(total_size, 1, this->area_id); +void DeviceInfo::calculate_size(ProtoSize &size) const { + size.add_uint32_field(1, this->device_id); + size.add_string_field(1, this->name_ref_.size()); + size.add_uint32_field(1, this->area_id); } #endif void DeviceInfoResponse::encode(ProtoWriteBuffer buffer) const { @@ -130,52 +130,52 @@ void DeviceInfoResponse::encode(ProtoWriteBuffer buffer) const { buffer.encode_message(22, this->area); #endif } -void DeviceInfoResponse::calculate_size(uint32_t &total_size) const { +void DeviceInfoResponse::calculate_size(ProtoSize &size) const { #ifdef USE_API_PASSWORD - ProtoSize::add_bool_field(total_size, 1, this->uses_password); + size.add_bool_field(1, this->uses_password); #endif - ProtoSize::add_string_field(total_size, 1, this->name_ref_.size()); - ProtoSize::add_string_field(total_size, 1, this->mac_address_ref_.size()); - ProtoSize::add_string_field(total_size, 1, this->esphome_version_ref_.size()); - ProtoSize::add_string_field(total_size, 1, this->compilation_time_ref_.size()); - ProtoSize::add_string_field(total_size, 1, this->model_ref_.size()); + size.add_string_field(1, this->name_ref_.size()); + size.add_string_field(1, this->mac_address_ref_.size()); + size.add_string_field(1, this->esphome_version_ref_.size()); + size.add_string_field(1, this->compilation_time_ref_.size()); + size.add_string_field(1, this->model_ref_.size()); #ifdef USE_DEEP_SLEEP - ProtoSize::add_bool_field(total_size, 1, this->has_deep_sleep); + size.add_bool_field(1, this->has_deep_sleep); #endif #ifdef ESPHOME_PROJECT_NAME - ProtoSize::add_string_field(total_size, 1, this->project_name_ref_.size()); + size.add_string_field(1, this->project_name_ref_.size()); #endif #ifdef ESPHOME_PROJECT_NAME - ProtoSize::add_string_field(total_size, 1, this->project_version_ref_.size()); + size.add_string_field(1, this->project_version_ref_.size()); #endif #ifdef USE_WEBSERVER - ProtoSize::add_uint32_field(total_size, 1, this->webserver_port); + size.add_uint32_field(1, this->webserver_port); #endif #ifdef USE_BLUETOOTH_PROXY - ProtoSize::add_uint32_field(total_size, 1, this->bluetooth_proxy_feature_flags); + size.add_uint32_field(1, this->bluetooth_proxy_feature_flags); #endif - ProtoSize::add_string_field(total_size, 1, this->manufacturer_ref_.size()); - ProtoSize::add_string_field(total_size, 1, this->friendly_name_ref_.size()); + size.add_string_field(1, this->manufacturer_ref_.size()); + size.add_string_field(1, this->friendly_name_ref_.size()); #ifdef USE_VOICE_ASSISTANT - ProtoSize::add_uint32_field(total_size, 2, this->voice_assistant_feature_flags); + size.add_uint32_field(2, this->voice_assistant_feature_flags); #endif #ifdef USE_AREAS - ProtoSize::add_string_field(total_size, 2, this->suggested_area_ref_.size()); + size.add_string_field(2, this->suggested_area_ref_.size()); #endif #ifdef USE_BLUETOOTH_PROXY - ProtoSize::add_string_field(total_size, 2, this->bluetooth_mac_address_ref_.size()); + size.add_string_field(2, this->bluetooth_mac_address_ref_.size()); #endif #ifdef USE_API_NOISE - ProtoSize::add_bool_field(total_size, 2, this->api_encryption_supported); + size.add_bool_field(2, this->api_encryption_supported); #endif #ifdef USE_DEVICES - ProtoSize::add_repeated_message(total_size, 2, this->devices); + size.add_repeated_message(2, this->devices); #endif #ifdef USE_AREAS - ProtoSize::add_repeated_message(total_size, 2, this->areas); + size.add_repeated_message(2, this->areas); #endif #ifdef USE_AREAS - ProtoSize::add_message_object(total_size, 2, this->area); + size.add_message_object(2, this->area); #endif } #ifdef USE_BINARY_SENSOR @@ -194,19 +194,19 @@ void ListEntitiesBinarySensorResponse::encode(ProtoWriteBuffer buffer) const { buffer.encode_uint32(10, this->device_id); #endif } -void ListEntitiesBinarySensorResponse::calculate_size(uint32_t &total_size) const { - ProtoSize::add_string_field(total_size, 1, this->object_id_ref_.size()); - ProtoSize::add_fixed32_field(total_size, 1, this->key); - ProtoSize::add_string_field(total_size, 1, this->name_ref_.size()); - ProtoSize::add_string_field(total_size, 1, this->device_class_ref_.size()); - ProtoSize::add_bool_field(total_size, 1, this->is_status_binary_sensor); - ProtoSize::add_bool_field(total_size, 1, this->disabled_by_default); +void ListEntitiesBinarySensorResponse::calculate_size(ProtoSize &size) const { + size.add_string_field(1, this->object_id_ref_.size()); + size.add_fixed32_field(1, this->key); + size.add_string_field(1, this->name_ref_.size()); + size.add_string_field(1, this->device_class_ref_.size()); + size.add_bool_field(1, this->is_status_binary_sensor); + size.add_bool_field(1, this->disabled_by_default); #ifdef USE_ENTITY_ICON - ProtoSize::add_string_field(total_size, 1, this->icon_ref_.size()); + size.add_string_field(1, this->icon_ref_.size()); #endif - ProtoSize::add_enum_field(total_size, 1, static_cast(this->entity_category)); + size.add_enum_field(1, static_cast(this->entity_category)); #ifdef USE_DEVICES - ProtoSize::add_uint32_field(total_size, 1, this->device_id); + size.add_uint32_field(1, this->device_id); #endif } void BinarySensorStateResponse::encode(ProtoWriteBuffer buffer) const { @@ -217,12 +217,12 @@ void BinarySensorStateResponse::encode(ProtoWriteBuffer buffer) const { buffer.encode_uint32(4, this->device_id); #endif } -void BinarySensorStateResponse::calculate_size(uint32_t &total_size) const { - ProtoSize::add_fixed32_field(total_size, 1, this->key); - ProtoSize::add_bool_field(total_size, 1, this->state); - ProtoSize::add_bool_field(total_size, 1, this->missing_state); +void BinarySensorStateResponse::calculate_size(ProtoSize &size) const { + size.add_fixed32_field(1, this->key); + size.add_bool_field(1, this->state); + size.add_bool_field(1, this->missing_state); #ifdef USE_DEVICES - ProtoSize::add_uint32_field(total_size, 1, this->device_id); + size.add_uint32_field(1, this->device_id); #endif } #endif @@ -245,22 +245,22 @@ void ListEntitiesCoverResponse::encode(ProtoWriteBuffer buffer) const { buffer.encode_uint32(13, this->device_id); #endif } -void ListEntitiesCoverResponse::calculate_size(uint32_t &total_size) const { - ProtoSize::add_string_field(total_size, 1, this->object_id_ref_.size()); - ProtoSize::add_fixed32_field(total_size, 1, this->key); - ProtoSize::add_string_field(total_size, 1, this->name_ref_.size()); - ProtoSize::add_bool_field(total_size, 1, this->assumed_state); - ProtoSize::add_bool_field(total_size, 1, this->supports_position); - ProtoSize::add_bool_field(total_size, 1, this->supports_tilt); - ProtoSize::add_string_field(total_size, 1, this->device_class_ref_.size()); - ProtoSize::add_bool_field(total_size, 1, this->disabled_by_default); +void ListEntitiesCoverResponse::calculate_size(ProtoSize &size) const { + size.add_string_field(1, this->object_id_ref_.size()); + size.add_fixed32_field(1, this->key); + size.add_string_field(1, this->name_ref_.size()); + size.add_bool_field(1, this->assumed_state); + size.add_bool_field(1, this->supports_position); + size.add_bool_field(1, this->supports_tilt); + size.add_string_field(1, this->device_class_ref_.size()); + size.add_bool_field(1, this->disabled_by_default); #ifdef USE_ENTITY_ICON - ProtoSize::add_string_field(total_size, 1, this->icon_ref_.size()); + size.add_string_field(1, this->icon_ref_.size()); #endif - ProtoSize::add_enum_field(total_size, 1, static_cast(this->entity_category)); - ProtoSize::add_bool_field(total_size, 1, this->supports_stop); + size.add_enum_field(1, static_cast(this->entity_category)); + size.add_bool_field(1, this->supports_stop); #ifdef USE_DEVICES - ProtoSize::add_uint32_field(total_size, 1, this->device_id); + size.add_uint32_field(1, this->device_id); #endif } void CoverStateResponse::encode(ProtoWriteBuffer buffer) const { @@ -272,13 +272,13 @@ void CoverStateResponse::encode(ProtoWriteBuffer buffer) const { buffer.encode_uint32(6, this->device_id); #endif } -void CoverStateResponse::calculate_size(uint32_t &total_size) const { - ProtoSize::add_fixed32_field(total_size, 1, this->key); - ProtoSize::add_float_field(total_size, 1, this->position); - ProtoSize::add_float_field(total_size, 1, this->tilt); - ProtoSize::add_enum_field(total_size, 1, static_cast(this->current_operation)); +void CoverStateResponse::calculate_size(ProtoSize &size) const { + size.add_fixed32_field(1, this->key); + size.add_float_field(1, this->position); + size.add_float_field(1, this->tilt); + size.add_enum_field(1, static_cast(this->current_operation)); #ifdef USE_DEVICES - ProtoSize::add_uint32_field(total_size, 1, this->device_id); + size.add_uint32_field(1, this->device_id); #endif } bool CoverCommandRequest::decode_varint(uint32_t field_id, ProtoVarInt value) { @@ -340,26 +340,26 @@ void ListEntitiesFanResponse::encode(ProtoWriteBuffer buffer) const { buffer.encode_uint32(13, this->device_id); #endif } -void ListEntitiesFanResponse::calculate_size(uint32_t &total_size) const { - ProtoSize::add_string_field(total_size, 1, this->object_id_ref_.size()); - ProtoSize::add_fixed32_field(total_size, 1, this->key); - ProtoSize::add_string_field(total_size, 1, this->name_ref_.size()); - ProtoSize::add_bool_field(total_size, 1, this->supports_oscillation); - ProtoSize::add_bool_field(total_size, 1, this->supports_speed); - ProtoSize::add_bool_field(total_size, 1, this->supports_direction); - ProtoSize::add_int32_field(total_size, 1, this->supported_speed_count); - ProtoSize::add_bool_field(total_size, 1, this->disabled_by_default); +void ListEntitiesFanResponse::calculate_size(ProtoSize &size) const { + size.add_string_field(1, this->object_id_ref_.size()); + size.add_fixed32_field(1, this->key); + size.add_string_field(1, this->name_ref_.size()); + size.add_bool_field(1, this->supports_oscillation); + size.add_bool_field(1, this->supports_speed); + size.add_bool_field(1, this->supports_direction); + size.add_int32_field(1, this->supported_speed_count); + size.add_bool_field(1, this->disabled_by_default); #ifdef USE_ENTITY_ICON - ProtoSize::add_string_field(total_size, 1, this->icon_ref_.size()); + size.add_string_field(1, this->icon_ref_.size()); #endif - ProtoSize::add_enum_field(total_size, 1, static_cast(this->entity_category)); + size.add_enum_field(1, static_cast(this->entity_category)); if (!this->supported_preset_modes.empty()) { for (const auto &it : this->supported_preset_modes) { - ProtoSize::add_string_field_repeated(total_size, 1, it); + size.add_string_field_repeated(1, it); } } #ifdef USE_DEVICES - ProtoSize::add_uint32_field(total_size, 1, this->device_id); + size.add_uint32_field(1, this->device_id); #endif } void FanStateResponse::encode(ProtoWriteBuffer buffer) const { @@ -373,15 +373,15 @@ void FanStateResponse::encode(ProtoWriteBuffer buffer) const { buffer.encode_uint32(8, this->device_id); #endif } -void FanStateResponse::calculate_size(uint32_t &total_size) const { - ProtoSize::add_fixed32_field(total_size, 1, this->key); - ProtoSize::add_bool_field(total_size, 1, this->state); - ProtoSize::add_bool_field(total_size, 1, this->oscillating); - ProtoSize::add_enum_field(total_size, 1, static_cast(this->direction)); - ProtoSize::add_int32_field(total_size, 1, this->speed_level); - ProtoSize::add_string_field(total_size, 1, this->preset_mode_ref_.size()); +void FanStateResponse::calculate_size(ProtoSize &size) const { + size.add_fixed32_field(1, this->key); + size.add_bool_field(1, this->state); + size.add_bool_field(1, this->oscillating); + size.add_enum_field(1, static_cast(this->direction)); + size.add_int32_field(1, this->speed_level); + size.add_string_field(1, this->preset_mode_ref_.size()); #ifdef USE_DEVICES - ProtoSize::add_uint32_field(total_size, 1, this->device_id); + size.add_uint32_field(1, this->device_id); #endif } bool FanCommandRequest::decode_varint(uint32_t field_id, ProtoVarInt value) { @@ -466,29 +466,29 @@ void ListEntitiesLightResponse::encode(ProtoWriteBuffer buffer) const { buffer.encode_uint32(16, this->device_id); #endif } -void ListEntitiesLightResponse::calculate_size(uint32_t &total_size) const { - ProtoSize::add_string_field(total_size, 1, this->object_id_ref_.size()); - ProtoSize::add_fixed32_field(total_size, 1, this->key); - ProtoSize::add_string_field(total_size, 1, this->name_ref_.size()); +void ListEntitiesLightResponse::calculate_size(ProtoSize &size) const { + size.add_string_field(1, this->object_id_ref_.size()); + size.add_fixed32_field(1, this->key); + size.add_string_field(1, this->name_ref_.size()); if (!this->supported_color_modes.empty()) { for (const auto &it : this->supported_color_modes) { - ProtoSize::add_enum_field_repeated(total_size, 1, static_cast(it)); + size.add_enum_field_repeated(1, static_cast(it)); } } - ProtoSize::add_float_field(total_size, 1, this->min_mireds); - ProtoSize::add_float_field(total_size, 1, this->max_mireds); + size.add_float_field(1, this->min_mireds); + size.add_float_field(1, this->max_mireds); if (!this->effects.empty()) { for (const auto &it : this->effects) { - ProtoSize::add_string_field_repeated(total_size, 1, it); + size.add_string_field_repeated(1, it); } } - ProtoSize::add_bool_field(total_size, 1, this->disabled_by_default); + size.add_bool_field(1, this->disabled_by_default); #ifdef USE_ENTITY_ICON - ProtoSize::add_string_field(total_size, 1, this->icon_ref_.size()); + size.add_string_field(1, this->icon_ref_.size()); #endif - ProtoSize::add_enum_field(total_size, 1, static_cast(this->entity_category)); + size.add_enum_field(1, static_cast(this->entity_category)); #ifdef USE_DEVICES - ProtoSize::add_uint32_field(total_size, 2, this->device_id); + size.add_uint32_field(2, this->device_id); #endif } void LightStateResponse::encode(ProtoWriteBuffer buffer) const { @@ -509,22 +509,22 @@ void LightStateResponse::encode(ProtoWriteBuffer buffer) const { buffer.encode_uint32(14, this->device_id); #endif } -void LightStateResponse::calculate_size(uint32_t &total_size) const { - ProtoSize::add_fixed32_field(total_size, 1, this->key); - ProtoSize::add_bool_field(total_size, 1, this->state); - ProtoSize::add_float_field(total_size, 1, this->brightness); - ProtoSize::add_enum_field(total_size, 1, static_cast(this->color_mode)); - ProtoSize::add_float_field(total_size, 1, this->color_brightness); - ProtoSize::add_float_field(total_size, 1, this->red); - ProtoSize::add_float_field(total_size, 1, this->green); - ProtoSize::add_float_field(total_size, 1, this->blue); - ProtoSize::add_float_field(total_size, 1, this->white); - ProtoSize::add_float_field(total_size, 1, this->color_temperature); - ProtoSize::add_float_field(total_size, 1, this->cold_white); - ProtoSize::add_float_field(total_size, 1, this->warm_white); - ProtoSize::add_string_field(total_size, 1, this->effect_ref_.size()); +void LightStateResponse::calculate_size(ProtoSize &size) const { + size.add_fixed32_field(1, this->key); + size.add_bool_field(1, this->state); + size.add_float_field(1, this->brightness); + size.add_enum_field(1, static_cast(this->color_mode)); + size.add_float_field(1, this->color_brightness); + size.add_float_field(1, this->red); + size.add_float_field(1, this->green); + size.add_float_field(1, this->blue); + size.add_float_field(1, this->white); + size.add_float_field(1, this->color_temperature); + size.add_float_field(1, this->cold_white); + size.add_float_field(1, this->warm_white); + size.add_string_field(1, this->effect_ref_.size()); #ifdef USE_DEVICES - ProtoSize::add_uint32_field(total_size, 1, this->device_id); + size.add_uint32_field(1, this->device_id); #endif } bool LightCommandRequest::decode_varint(uint32_t field_id, ProtoVarInt value) { @@ -654,22 +654,22 @@ void ListEntitiesSensorResponse::encode(ProtoWriteBuffer buffer) const { buffer.encode_uint32(14, this->device_id); #endif } -void ListEntitiesSensorResponse::calculate_size(uint32_t &total_size) const { - ProtoSize::add_string_field(total_size, 1, this->object_id_ref_.size()); - ProtoSize::add_fixed32_field(total_size, 1, this->key); - ProtoSize::add_string_field(total_size, 1, this->name_ref_.size()); +void ListEntitiesSensorResponse::calculate_size(ProtoSize &size) const { + size.add_string_field(1, this->object_id_ref_.size()); + size.add_fixed32_field(1, this->key); + size.add_string_field(1, this->name_ref_.size()); #ifdef USE_ENTITY_ICON - ProtoSize::add_string_field(total_size, 1, this->icon_ref_.size()); + size.add_string_field(1, this->icon_ref_.size()); #endif - ProtoSize::add_string_field(total_size, 1, this->unit_of_measurement_ref_.size()); - ProtoSize::add_int32_field(total_size, 1, this->accuracy_decimals); - ProtoSize::add_bool_field(total_size, 1, this->force_update); - ProtoSize::add_string_field(total_size, 1, this->device_class_ref_.size()); - ProtoSize::add_enum_field(total_size, 1, static_cast(this->state_class)); - ProtoSize::add_bool_field(total_size, 1, this->disabled_by_default); - ProtoSize::add_enum_field(total_size, 1, static_cast(this->entity_category)); + size.add_string_field(1, this->unit_of_measurement_ref_.size()); + size.add_int32_field(1, this->accuracy_decimals); + size.add_bool_field(1, this->force_update); + size.add_string_field(1, this->device_class_ref_.size()); + size.add_enum_field(1, static_cast(this->state_class)); + size.add_bool_field(1, this->disabled_by_default); + size.add_enum_field(1, static_cast(this->entity_category)); #ifdef USE_DEVICES - ProtoSize::add_uint32_field(total_size, 1, this->device_id); + size.add_uint32_field(1, this->device_id); #endif } void SensorStateResponse::encode(ProtoWriteBuffer buffer) const { @@ -680,12 +680,12 @@ void SensorStateResponse::encode(ProtoWriteBuffer buffer) const { buffer.encode_uint32(4, this->device_id); #endif } -void SensorStateResponse::calculate_size(uint32_t &total_size) const { - ProtoSize::add_fixed32_field(total_size, 1, this->key); - ProtoSize::add_float_field(total_size, 1, this->state); - ProtoSize::add_bool_field(total_size, 1, this->missing_state); +void SensorStateResponse::calculate_size(ProtoSize &size) const { + size.add_fixed32_field(1, this->key); + size.add_float_field(1, this->state); + size.add_bool_field(1, this->missing_state); #ifdef USE_DEVICES - ProtoSize::add_uint32_field(total_size, 1, this->device_id); + size.add_uint32_field(1, this->device_id); #endif } #endif @@ -705,19 +705,19 @@ void ListEntitiesSwitchResponse::encode(ProtoWriteBuffer buffer) const { buffer.encode_uint32(10, this->device_id); #endif } -void ListEntitiesSwitchResponse::calculate_size(uint32_t &total_size) const { - ProtoSize::add_string_field(total_size, 1, this->object_id_ref_.size()); - ProtoSize::add_fixed32_field(total_size, 1, this->key); - ProtoSize::add_string_field(total_size, 1, this->name_ref_.size()); +void ListEntitiesSwitchResponse::calculate_size(ProtoSize &size) const { + size.add_string_field(1, this->object_id_ref_.size()); + size.add_fixed32_field(1, this->key); + size.add_string_field(1, this->name_ref_.size()); #ifdef USE_ENTITY_ICON - ProtoSize::add_string_field(total_size, 1, this->icon_ref_.size()); + size.add_string_field(1, this->icon_ref_.size()); #endif - ProtoSize::add_bool_field(total_size, 1, this->assumed_state); - ProtoSize::add_bool_field(total_size, 1, this->disabled_by_default); - ProtoSize::add_enum_field(total_size, 1, static_cast(this->entity_category)); - ProtoSize::add_string_field(total_size, 1, this->device_class_ref_.size()); + size.add_bool_field(1, this->assumed_state); + size.add_bool_field(1, this->disabled_by_default); + size.add_enum_field(1, static_cast(this->entity_category)); + size.add_string_field(1, this->device_class_ref_.size()); #ifdef USE_DEVICES - ProtoSize::add_uint32_field(total_size, 1, this->device_id); + size.add_uint32_field(1, this->device_id); #endif } void SwitchStateResponse::encode(ProtoWriteBuffer buffer) const { @@ -727,11 +727,11 @@ void SwitchStateResponse::encode(ProtoWriteBuffer buffer) const { buffer.encode_uint32(3, this->device_id); #endif } -void SwitchStateResponse::calculate_size(uint32_t &total_size) const { - ProtoSize::add_fixed32_field(total_size, 1, this->key); - ProtoSize::add_bool_field(total_size, 1, this->state); +void SwitchStateResponse::calculate_size(ProtoSize &size) const { + size.add_fixed32_field(1, this->key); + size.add_bool_field(1, this->state); #ifdef USE_DEVICES - ProtoSize::add_uint32_field(total_size, 1, this->device_id); + size.add_uint32_field(1, this->device_id); #endif } bool SwitchCommandRequest::decode_varint(uint32_t field_id, ProtoVarInt value) { @@ -775,18 +775,18 @@ void ListEntitiesTextSensorResponse::encode(ProtoWriteBuffer buffer) const { buffer.encode_uint32(9, this->device_id); #endif } -void ListEntitiesTextSensorResponse::calculate_size(uint32_t &total_size) const { - ProtoSize::add_string_field(total_size, 1, this->object_id_ref_.size()); - ProtoSize::add_fixed32_field(total_size, 1, this->key); - ProtoSize::add_string_field(total_size, 1, this->name_ref_.size()); +void ListEntitiesTextSensorResponse::calculate_size(ProtoSize &size) const { + size.add_string_field(1, this->object_id_ref_.size()); + size.add_fixed32_field(1, this->key); + size.add_string_field(1, this->name_ref_.size()); #ifdef USE_ENTITY_ICON - ProtoSize::add_string_field(total_size, 1, this->icon_ref_.size()); + size.add_string_field(1, this->icon_ref_.size()); #endif - ProtoSize::add_bool_field(total_size, 1, this->disabled_by_default); - ProtoSize::add_enum_field(total_size, 1, static_cast(this->entity_category)); - ProtoSize::add_string_field(total_size, 1, this->device_class_ref_.size()); + size.add_bool_field(1, this->disabled_by_default); + size.add_enum_field(1, static_cast(this->entity_category)); + size.add_string_field(1, this->device_class_ref_.size()); #ifdef USE_DEVICES - ProtoSize::add_uint32_field(total_size, 1, this->device_id); + size.add_uint32_field(1, this->device_id); #endif } void TextSensorStateResponse::encode(ProtoWriteBuffer buffer) const { @@ -797,12 +797,12 @@ void TextSensorStateResponse::encode(ProtoWriteBuffer buffer) const { buffer.encode_uint32(4, this->device_id); #endif } -void TextSensorStateResponse::calculate_size(uint32_t &total_size) const { - ProtoSize::add_fixed32_field(total_size, 1, this->key); - ProtoSize::add_string_field(total_size, 1, this->state_ref_.size()); - ProtoSize::add_bool_field(total_size, 1, this->missing_state); +void TextSensorStateResponse::calculate_size(ProtoSize &size) const { + size.add_fixed32_field(1, this->key); + size.add_string_field(1, this->state_ref_.size()); + size.add_bool_field(1, this->missing_state); #ifdef USE_DEVICES - ProtoSize::add_uint32_field(total_size, 1, this->device_id); + size.add_uint32_field(1, this->device_id); #endif } #endif @@ -823,9 +823,9 @@ void SubscribeLogsResponse::encode(ProtoWriteBuffer buffer) const { buffer.encode_uint32(1, static_cast(this->level)); buffer.encode_bytes(3, this->message_ptr_, this->message_len_); } -void SubscribeLogsResponse::calculate_size(uint32_t &total_size) const { - ProtoSize::add_enum_field(total_size, 1, static_cast(this->level)); - ProtoSize::add_bytes_field(total_size, 1, this->message_len_); +void SubscribeLogsResponse::calculate_size(ProtoSize &size) const { + size.add_enum_field(1, static_cast(this->level)); + size.add_bytes_field(1, this->message_len_); } #ifdef USE_API_NOISE bool NoiseEncryptionSetKeyRequest::decode_length(uint32_t field_id, ProtoLengthDelimited value) { @@ -839,17 +839,17 @@ bool NoiseEncryptionSetKeyRequest::decode_length(uint32_t field_id, ProtoLengthD return true; } void NoiseEncryptionSetKeyResponse::encode(ProtoWriteBuffer buffer) const { buffer.encode_bool(1, this->success); } -void NoiseEncryptionSetKeyResponse::calculate_size(uint32_t &total_size) const { - ProtoSize::add_bool_field(total_size, 1, this->success); +} +void NoiseEncryptionSetKeyResponse::calculate_size(ProtoSize &size) const { size.add_bool_field(1, this->success); } } #endif void HomeassistantServiceMap::encode(ProtoWriteBuffer buffer) const { buffer.encode_string(1, this->key_ref_); buffer.encode_string(2, this->value_ref_); } -void HomeassistantServiceMap::calculate_size(uint32_t &total_size) const { - ProtoSize::add_string_field(total_size, 1, this->key_ref_.size()); - ProtoSize::add_string_field(total_size, 1, this->value_ref_.size()); +void HomeassistantServiceMap::calculate_size(ProtoSize &size) const { + size.add_string_field(1, this->key_ref_.size()); + size.add_string_field(1, this->value_ref_.size()); } void HomeassistantServiceResponse::encode(ProtoWriteBuffer buffer) const { buffer.encode_string(1, this->service_ref_); @@ -864,12 +864,12 @@ void HomeassistantServiceResponse::encode(ProtoWriteBuffer buffer) const { } buffer.encode_bool(5, this->is_event); } -void HomeassistantServiceResponse::calculate_size(uint32_t &total_size) const { - ProtoSize::add_string_field(total_size, 1, this->service_ref_.size()); - ProtoSize::add_repeated_message(total_size, 1, this->data); - ProtoSize::add_repeated_message(total_size, 1, this->data_template); - ProtoSize::add_repeated_message(total_size, 1, this->variables); - ProtoSize::add_bool_field(total_size, 1, this->is_event); +void HomeassistantServiceResponse::calculate_size(ProtoSize &size) const { + size.add_string_field(1, this->service_ref_.size()); + size.add_repeated_message(1, this->data); + size.add_repeated_message(1, this->data_template); + size.add_repeated_message(1, this->variables); + size.add_bool_field(1, this->is_event); } #ifdef USE_API_HOMEASSISTANT_STATES void SubscribeHomeAssistantStateResponse::encode(ProtoWriteBuffer buffer) const { @@ -877,10 +877,10 @@ void SubscribeHomeAssistantStateResponse::encode(ProtoWriteBuffer buffer) const buffer.encode_string(2, this->attribute_ref_); buffer.encode_bool(3, this->once); } -void SubscribeHomeAssistantStateResponse::calculate_size(uint32_t &total_size) const { - ProtoSize::add_string_field(total_size, 1, this->entity_id_ref_.size()); - ProtoSize::add_string_field(total_size, 1, this->attribute_ref_.size()); - ProtoSize::add_bool_field(total_size, 1, this->once); +void SubscribeHomeAssistantStateResponse::calculate_size(ProtoSize &size) const { + size.add_string_field(1, this->entity_id_ref_.size()); + size.add_string_field(1, this->attribute_ref_.size()); + size.add_bool_field(1, this->once); } bool HomeAssistantStateResponse::decode_length(uint32_t field_id, ProtoLengthDelimited value) { switch (field_id) { @@ -910,17 +910,17 @@ bool GetTimeResponse::decode_32bit(uint32_t field_id, Proto32Bit value) { return true; } void GetTimeResponse::encode(ProtoWriteBuffer buffer) const { buffer.encode_fixed32(1, this->epoch_seconds); } -void GetTimeResponse::calculate_size(uint32_t &total_size) const { - ProtoSize::add_fixed32_field(total_size, 1, this->epoch_seconds); +} +void GetTimeResponse::calculate_size(ProtoSize &size) const { size.add_fixed32_field(1, this->epoch_seconds); } } #ifdef USE_API_SERVICES void ListEntitiesServicesArgument::encode(ProtoWriteBuffer buffer) const { buffer.encode_string(1, this->name_ref_); buffer.encode_uint32(2, static_cast(this->type)); } -void ListEntitiesServicesArgument::calculate_size(uint32_t &total_size) const { - ProtoSize::add_string_field(total_size, 1, this->name_ref_.size()); - ProtoSize::add_enum_field(total_size, 1, static_cast(this->type)); +void ListEntitiesServicesArgument::calculate_size(ProtoSize &size) const { + size.add_string_field(1, this->name_ref_.size()); + size.add_enum_field(1, static_cast(this->type)); } void ListEntitiesServicesResponse::encode(ProtoWriteBuffer buffer) const { buffer.encode_string(1, this->name_ref_); @@ -929,10 +929,10 @@ void ListEntitiesServicesResponse::encode(ProtoWriteBuffer buffer) const { buffer.encode_message(3, it, true); } } -void ListEntitiesServicesResponse::calculate_size(uint32_t &total_size) const { - ProtoSize::add_string_field(total_size, 1, this->name_ref_.size()); - ProtoSize::add_fixed32_field(total_size, 1, this->key); - ProtoSize::add_repeated_message(total_size, 1, this->args); +void ListEntitiesServicesResponse::calculate_size(ProtoSize &size) const { + size.add_string_field(1, this->name_ref_.size()); + size.add_fixed32_field(1, this->key); + size.add_repeated_message(1, this->args); } bool ExecuteServiceArgument::decode_varint(uint32_t field_id, ProtoVarInt value) { switch (field_id) { @@ -1018,17 +1018,17 @@ void ListEntitiesCameraResponse::encode(ProtoWriteBuffer buffer) const { buffer.encode_uint32(8, this->device_id); #endif } -void ListEntitiesCameraResponse::calculate_size(uint32_t &total_size) const { - ProtoSize::add_string_field(total_size, 1, this->object_id_ref_.size()); - ProtoSize::add_fixed32_field(total_size, 1, this->key); - ProtoSize::add_string_field(total_size, 1, this->name_ref_.size()); - ProtoSize::add_bool_field(total_size, 1, this->disabled_by_default); +void ListEntitiesCameraResponse::calculate_size(ProtoSize &size) const { + size.add_string_field(1, this->object_id_ref_.size()); + size.add_fixed32_field(1, this->key); + size.add_string_field(1, this->name_ref_.size()); + size.add_bool_field(1, this->disabled_by_default); #ifdef USE_ENTITY_ICON - ProtoSize::add_string_field(total_size, 1, this->icon_ref_.size()); + size.add_string_field(1, this->icon_ref_.size()); #endif - ProtoSize::add_enum_field(total_size, 1, static_cast(this->entity_category)); + size.add_enum_field(1, static_cast(this->entity_category)); #ifdef USE_DEVICES - ProtoSize::add_uint32_field(total_size, 1, this->device_id); + size.add_uint32_field(1, this->device_id); #endif } void CameraImageResponse::encode(ProtoWriteBuffer buffer) const { @@ -1039,12 +1039,12 @@ void CameraImageResponse::encode(ProtoWriteBuffer buffer) const { buffer.encode_uint32(4, this->device_id); #endif } -void CameraImageResponse::calculate_size(uint32_t &total_size) const { - ProtoSize::add_fixed32_field(total_size, 1, this->key); - ProtoSize::add_bytes_field(total_size, 1, this->data_len_); - ProtoSize::add_bool_field(total_size, 1, this->done); +void CameraImageResponse::calculate_size(ProtoSize &size) const { + size.add_fixed32_field(1, this->key); + size.add_bytes_field(1, this->data_len_); + size.add_bool_field(1, this->done); #ifdef USE_DEVICES - ProtoSize::add_uint32_field(total_size, 1, this->device_id); + size.add_uint32_field(1, this->device_id); #endif } bool CameraImageRequest::decode_varint(uint32_t field_id, ProtoVarInt value) { @@ -1104,58 +1104,58 @@ void ListEntitiesClimateResponse::encode(ProtoWriteBuffer buffer) const { buffer.encode_uint32(26, this->device_id); #endif } -void ListEntitiesClimateResponse::calculate_size(uint32_t &total_size) const { - ProtoSize::add_string_field(total_size, 1, this->object_id_ref_.size()); - ProtoSize::add_fixed32_field(total_size, 1, this->key); - ProtoSize::add_string_field(total_size, 1, this->name_ref_.size()); - ProtoSize::add_bool_field(total_size, 1, this->supports_current_temperature); - ProtoSize::add_bool_field(total_size, 1, this->supports_two_point_target_temperature); +void ListEntitiesClimateResponse::calculate_size(ProtoSize &size) const { + size.add_string_field(1, this->object_id_ref_.size()); + size.add_fixed32_field(1, this->key); + size.add_string_field(1, this->name_ref_.size()); + size.add_bool_field(1, this->supports_current_temperature); + size.add_bool_field(1, this->supports_two_point_target_temperature); if (!this->supported_modes.empty()) { for (const auto &it : this->supported_modes) { - ProtoSize::add_enum_field_repeated(total_size, 1, static_cast(it)); + size.add_enum_field_repeated(1, static_cast(it)); } } - ProtoSize::add_float_field(total_size, 1, this->visual_min_temperature); - ProtoSize::add_float_field(total_size, 1, this->visual_max_temperature); - ProtoSize::add_float_field(total_size, 1, this->visual_target_temperature_step); - ProtoSize::add_bool_field(total_size, 1, this->supports_action); + size.add_float_field(1, this->visual_min_temperature); + size.add_float_field(1, this->visual_max_temperature); + size.add_float_field(1, this->visual_target_temperature_step); + size.add_bool_field(1, this->supports_action); if (!this->supported_fan_modes.empty()) { for (const auto &it : this->supported_fan_modes) { - ProtoSize::add_enum_field_repeated(total_size, 1, static_cast(it)); + size.add_enum_field_repeated(1, static_cast(it)); } } if (!this->supported_swing_modes.empty()) { for (const auto &it : this->supported_swing_modes) { - ProtoSize::add_enum_field_repeated(total_size, 1, static_cast(it)); + size.add_enum_field_repeated(1, static_cast(it)); } } if (!this->supported_custom_fan_modes.empty()) { for (const auto &it : this->supported_custom_fan_modes) { - ProtoSize::add_string_field_repeated(total_size, 1, it); + size.add_string_field_repeated(1, it); } } if (!this->supported_presets.empty()) { for (const auto &it : this->supported_presets) { - ProtoSize::add_enum_field_repeated(total_size, 2, static_cast(it)); + size.add_enum_field_repeated(2, static_cast(it)); } } if (!this->supported_custom_presets.empty()) { for (const auto &it : this->supported_custom_presets) { - ProtoSize::add_string_field_repeated(total_size, 2, it); + size.add_string_field_repeated(2, it); } } - ProtoSize::add_bool_field(total_size, 2, this->disabled_by_default); + size.add_bool_field(2, this->disabled_by_default); #ifdef USE_ENTITY_ICON - ProtoSize::add_string_field(total_size, 2, this->icon_ref_.size()); + size.add_string_field(2, this->icon_ref_.size()); #endif - ProtoSize::add_enum_field(total_size, 2, static_cast(this->entity_category)); - ProtoSize::add_float_field(total_size, 2, this->visual_current_temperature_step); - ProtoSize::add_bool_field(total_size, 2, this->supports_current_humidity); - ProtoSize::add_bool_field(total_size, 2, this->supports_target_humidity); - ProtoSize::add_float_field(total_size, 2, this->visual_min_humidity); - ProtoSize::add_float_field(total_size, 2, this->visual_max_humidity); + size.add_enum_field(2, static_cast(this->entity_category)); + size.add_float_field(2, this->visual_current_temperature_step); + size.add_bool_field(2, this->supports_current_humidity); + size.add_bool_field(2, this->supports_target_humidity); + size.add_float_field(2, this->visual_min_humidity); + size.add_float_field(2, this->visual_max_humidity); #ifdef USE_DEVICES - ProtoSize::add_uint32_field(total_size, 2, this->device_id); + size.add_uint32_field(2, this->device_id); #endif } void ClimateStateResponse::encode(ProtoWriteBuffer buffer) const { @@ -1177,23 +1177,23 @@ void ClimateStateResponse::encode(ProtoWriteBuffer buffer) const { buffer.encode_uint32(16, this->device_id); #endif } -void ClimateStateResponse::calculate_size(uint32_t &total_size) const { - ProtoSize::add_fixed32_field(total_size, 1, this->key); - ProtoSize::add_enum_field(total_size, 1, static_cast(this->mode)); - ProtoSize::add_float_field(total_size, 1, this->current_temperature); - ProtoSize::add_float_field(total_size, 1, this->target_temperature); - ProtoSize::add_float_field(total_size, 1, this->target_temperature_low); - ProtoSize::add_float_field(total_size, 1, this->target_temperature_high); - ProtoSize::add_enum_field(total_size, 1, static_cast(this->action)); - ProtoSize::add_enum_field(total_size, 1, static_cast(this->fan_mode)); - ProtoSize::add_enum_field(total_size, 1, static_cast(this->swing_mode)); - ProtoSize::add_string_field(total_size, 1, this->custom_fan_mode_ref_.size()); - ProtoSize::add_enum_field(total_size, 1, static_cast(this->preset)); - ProtoSize::add_string_field(total_size, 1, this->custom_preset_ref_.size()); - ProtoSize::add_float_field(total_size, 1, this->current_humidity); - ProtoSize::add_float_field(total_size, 1, this->target_humidity); +void ClimateStateResponse::calculate_size(ProtoSize &size) const { + size.add_fixed32_field(1, this->key); + size.add_enum_field(1, static_cast(this->mode)); + size.add_float_field(1, this->current_temperature); + size.add_float_field(1, this->target_temperature); + size.add_float_field(1, this->target_temperature_low); + size.add_float_field(1, this->target_temperature_high); + size.add_enum_field(1, static_cast(this->action)); + size.add_enum_field(1, static_cast(this->fan_mode)); + size.add_enum_field(1, static_cast(this->swing_mode)); + size.add_string_field(1, this->custom_fan_mode_ref_.size()); + size.add_enum_field(1, static_cast(this->preset)); + size.add_string_field(1, this->custom_preset_ref_.size()); + size.add_float_field(1, this->current_humidity); + size.add_float_field(1, this->target_humidity); #ifdef USE_DEVICES - ProtoSize::add_uint32_field(total_size, 2, this->device_id); + size.add_uint32_field(2, this->device_id); #endif } bool ClimateCommandRequest::decode_varint(uint32_t field_id, ProtoVarInt value) { @@ -1306,23 +1306,23 @@ void ListEntitiesNumberResponse::encode(ProtoWriteBuffer buffer) const { buffer.encode_uint32(14, this->device_id); #endif } -void ListEntitiesNumberResponse::calculate_size(uint32_t &total_size) const { - ProtoSize::add_string_field(total_size, 1, this->object_id_ref_.size()); - ProtoSize::add_fixed32_field(total_size, 1, this->key); - ProtoSize::add_string_field(total_size, 1, this->name_ref_.size()); +void ListEntitiesNumberResponse::calculate_size(ProtoSize &size) const { + size.add_string_field(1, this->object_id_ref_.size()); + size.add_fixed32_field(1, this->key); + size.add_string_field(1, this->name_ref_.size()); #ifdef USE_ENTITY_ICON - ProtoSize::add_string_field(total_size, 1, this->icon_ref_.size()); + size.add_string_field(1, this->icon_ref_.size()); #endif - ProtoSize::add_float_field(total_size, 1, this->min_value); - ProtoSize::add_float_field(total_size, 1, this->max_value); - ProtoSize::add_float_field(total_size, 1, this->step); - ProtoSize::add_bool_field(total_size, 1, this->disabled_by_default); - ProtoSize::add_enum_field(total_size, 1, static_cast(this->entity_category)); - ProtoSize::add_string_field(total_size, 1, this->unit_of_measurement_ref_.size()); - ProtoSize::add_enum_field(total_size, 1, static_cast(this->mode)); - ProtoSize::add_string_field(total_size, 1, this->device_class_ref_.size()); + size.add_float_field(1, this->min_value); + size.add_float_field(1, this->max_value); + size.add_float_field(1, this->step); + size.add_bool_field(1, this->disabled_by_default); + size.add_enum_field(1, static_cast(this->entity_category)); + size.add_string_field(1, this->unit_of_measurement_ref_.size()); + size.add_enum_field(1, static_cast(this->mode)); + size.add_string_field(1, this->device_class_ref_.size()); #ifdef USE_DEVICES - ProtoSize::add_uint32_field(total_size, 1, this->device_id); + size.add_uint32_field(1, this->device_id); #endif } void NumberStateResponse::encode(ProtoWriteBuffer buffer) const { @@ -1333,12 +1333,12 @@ void NumberStateResponse::encode(ProtoWriteBuffer buffer) const { buffer.encode_uint32(4, this->device_id); #endif } -void NumberStateResponse::calculate_size(uint32_t &total_size) const { - ProtoSize::add_fixed32_field(total_size, 1, this->key); - ProtoSize::add_float_field(total_size, 1, this->state); - ProtoSize::add_bool_field(total_size, 1, this->missing_state); +void NumberStateResponse::calculate_size(ProtoSize &size) const { + size.add_fixed32_field(1, this->key); + size.add_float_field(1, this->state); + size.add_bool_field(1, this->missing_state); #ifdef USE_DEVICES - ProtoSize::add_uint32_field(total_size, 1, this->device_id); + size.add_uint32_field(1, this->device_id); #endif } bool NumberCommandRequest::decode_varint(uint32_t field_id, ProtoVarInt value) { @@ -1384,22 +1384,22 @@ void ListEntitiesSelectResponse::encode(ProtoWriteBuffer buffer) const { buffer.encode_uint32(9, this->device_id); #endif } -void ListEntitiesSelectResponse::calculate_size(uint32_t &total_size) const { - ProtoSize::add_string_field(total_size, 1, this->object_id_ref_.size()); - ProtoSize::add_fixed32_field(total_size, 1, this->key); - ProtoSize::add_string_field(total_size, 1, this->name_ref_.size()); +void ListEntitiesSelectResponse::calculate_size(ProtoSize &size) const { + size.add_string_field(1, this->object_id_ref_.size()); + size.add_fixed32_field(1, this->key); + size.add_string_field(1, this->name_ref_.size()); #ifdef USE_ENTITY_ICON - ProtoSize::add_string_field(total_size, 1, this->icon_ref_.size()); + size.add_string_field(1, this->icon_ref_.size()); #endif if (!this->options.empty()) { for (const auto &it : this->options) { - ProtoSize::add_string_field_repeated(total_size, 1, it); + size.add_string_field_repeated(1, it); } } - ProtoSize::add_bool_field(total_size, 1, this->disabled_by_default); - ProtoSize::add_enum_field(total_size, 1, static_cast(this->entity_category)); + size.add_bool_field(1, this->disabled_by_default); + size.add_enum_field(1, static_cast(this->entity_category)); #ifdef USE_DEVICES - ProtoSize::add_uint32_field(total_size, 1, this->device_id); + size.add_uint32_field(1, this->device_id); #endif } void SelectStateResponse::encode(ProtoWriteBuffer buffer) const { @@ -1410,12 +1410,12 @@ void SelectStateResponse::encode(ProtoWriteBuffer buffer) const { buffer.encode_uint32(4, this->device_id); #endif } -void SelectStateResponse::calculate_size(uint32_t &total_size) const { - ProtoSize::add_fixed32_field(total_size, 1, this->key); - ProtoSize::add_string_field(total_size, 1, this->state_ref_.size()); - ProtoSize::add_bool_field(total_size, 1, this->missing_state); +void SelectStateResponse::calculate_size(ProtoSize &size) const { + size.add_fixed32_field(1, this->key); + size.add_string_field(1, this->state_ref_.size()); + size.add_bool_field(1, this->missing_state); #ifdef USE_DEVICES - ProtoSize::add_uint32_field(total_size, 1, this->device_id); + size.add_uint32_field(1, this->device_id); #endif } bool SelectCommandRequest::decode_varint(uint32_t field_id, ProtoVarInt value) { @@ -1470,24 +1470,24 @@ void ListEntitiesSirenResponse::encode(ProtoWriteBuffer buffer) const { buffer.encode_uint32(11, this->device_id); #endif } -void ListEntitiesSirenResponse::calculate_size(uint32_t &total_size) const { - ProtoSize::add_string_field(total_size, 1, this->object_id_ref_.size()); - ProtoSize::add_fixed32_field(total_size, 1, this->key); - ProtoSize::add_string_field(total_size, 1, this->name_ref_.size()); +void ListEntitiesSirenResponse::calculate_size(ProtoSize &size) const { + size.add_string_field(1, this->object_id_ref_.size()); + size.add_fixed32_field(1, this->key); + size.add_string_field(1, this->name_ref_.size()); #ifdef USE_ENTITY_ICON - ProtoSize::add_string_field(total_size, 1, this->icon_ref_.size()); + size.add_string_field(1, this->icon_ref_.size()); #endif - ProtoSize::add_bool_field(total_size, 1, this->disabled_by_default); + size.add_bool_field(1, this->disabled_by_default); if (!this->tones.empty()) { for (const auto &it : this->tones) { - ProtoSize::add_string_field_repeated(total_size, 1, it); + size.add_string_field_repeated(1, it); } } - ProtoSize::add_bool_field(total_size, 1, this->supports_duration); - ProtoSize::add_bool_field(total_size, 1, this->supports_volume); - ProtoSize::add_enum_field(total_size, 1, static_cast(this->entity_category)); + size.add_bool_field(1, this->supports_duration); + size.add_bool_field(1, this->supports_volume); + size.add_enum_field(1, static_cast(this->entity_category)); #ifdef USE_DEVICES - ProtoSize::add_uint32_field(total_size, 1, this->device_id); + size.add_uint32_field(1, this->device_id); #endif } void SirenStateResponse::encode(ProtoWriteBuffer buffer) const { @@ -1497,11 +1497,11 @@ void SirenStateResponse::encode(ProtoWriteBuffer buffer) const { buffer.encode_uint32(3, this->device_id); #endif } -void SirenStateResponse::calculate_size(uint32_t &total_size) const { - ProtoSize::add_fixed32_field(total_size, 1, this->key); - ProtoSize::add_bool_field(total_size, 1, this->state); +void SirenStateResponse::calculate_size(ProtoSize &size) const { + size.add_fixed32_field(1, this->key); + size.add_bool_field(1, this->state); #ifdef USE_DEVICES - ProtoSize::add_uint32_field(total_size, 1, this->device_id); + size.add_uint32_field(1, this->device_id); #endif } bool SirenCommandRequest::decode_varint(uint32_t field_id, ProtoVarInt value) { @@ -1576,21 +1576,21 @@ void ListEntitiesLockResponse::encode(ProtoWriteBuffer buffer) const { buffer.encode_uint32(12, this->device_id); #endif } -void ListEntitiesLockResponse::calculate_size(uint32_t &total_size) const { - ProtoSize::add_string_field(total_size, 1, this->object_id_ref_.size()); - ProtoSize::add_fixed32_field(total_size, 1, this->key); - ProtoSize::add_string_field(total_size, 1, this->name_ref_.size()); +void ListEntitiesLockResponse::calculate_size(ProtoSize &size) const { + size.add_string_field(1, this->object_id_ref_.size()); + size.add_fixed32_field(1, this->key); + size.add_string_field(1, this->name_ref_.size()); #ifdef USE_ENTITY_ICON - ProtoSize::add_string_field(total_size, 1, this->icon_ref_.size()); + size.add_string_field(1, this->icon_ref_.size()); #endif - ProtoSize::add_bool_field(total_size, 1, this->disabled_by_default); - ProtoSize::add_enum_field(total_size, 1, static_cast(this->entity_category)); - ProtoSize::add_bool_field(total_size, 1, this->assumed_state); - ProtoSize::add_bool_field(total_size, 1, this->supports_open); - ProtoSize::add_bool_field(total_size, 1, this->requires_code); - ProtoSize::add_string_field(total_size, 1, this->code_format_ref_.size()); + size.add_bool_field(1, this->disabled_by_default); + size.add_enum_field(1, static_cast(this->entity_category)); + size.add_bool_field(1, this->assumed_state); + size.add_bool_field(1, this->supports_open); + size.add_bool_field(1, this->requires_code); + size.add_string_field(1, this->code_format_ref_.size()); #ifdef USE_DEVICES - ProtoSize::add_uint32_field(total_size, 1, this->device_id); + size.add_uint32_field(1, this->device_id); #endif } void LockStateResponse::encode(ProtoWriteBuffer buffer) const { @@ -1600,11 +1600,11 @@ void LockStateResponse::encode(ProtoWriteBuffer buffer) const { buffer.encode_uint32(3, this->device_id); #endif } -void LockStateResponse::calculate_size(uint32_t &total_size) const { - ProtoSize::add_fixed32_field(total_size, 1, this->key); - ProtoSize::add_enum_field(total_size, 1, static_cast(this->state)); +void LockStateResponse::calculate_size(ProtoSize &size) const { + size.add_fixed32_field(1, this->key); + size.add_enum_field(1, static_cast(this->state)); #ifdef USE_DEVICES - ProtoSize::add_uint32_field(total_size, 1, this->device_id); + size.add_uint32_field(1, this->device_id); #endif } bool LockCommandRequest::decode_varint(uint32_t field_id, ProtoVarInt value) { @@ -1661,18 +1661,18 @@ void ListEntitiesButtonResponse::encode(ProtoWriteBuffer buffer) const { buffer.encode_uint32(9, this->device_id); #endif } -void ListEntitiesButtonResponse::calculate_size(uint32_t &total_size) const { - ProtoSize::add_string_field(total_size, 1, this->object_id_ref_.size()); - ProtoSize::add_fixed32_field(total_size, 1, this->key); - ProtoSize::add_string_field(total_size, 1, this->name_ref_.size()); +void ListEntitiesButtonResponse::calculate_size(ProtoSize &size) const { + size.add_string_field(1, this->object_id_ref_.size()); + size.add_fixed32_field(1, this->key); + size.add_string_field(1, this->name_ref_.size()); #ifdef USE_ENTITY_ICON - ProtoSize::add_string_field(total_size, 1, this->icon_ref_.size()); + size.add_string_field(1, this->icon_ref_.size()); #endif - ProtoSize::add_bool_field(total_size, 1, this->disabled_by_default); - ProtoSize::add_enum_field(total_size, 1, static_cast(this->entity_category)); - ProtoSize::add_string_field(total_size, 1, this->device_class_ref_.size()); + size.add_bool_field(1, this->disabled_by_default); + size.add_enum_field(1, static_cast(this->entity_category)); + size.add_string_field(1, this->device_class_ref_.size()); #ifdef USE_DEVICES - ProtoSize::add_uint32_field(total_size, 1, this->device_id); + size.add_uint32_field(1, this->device_id); #endif } bool ButtonCommandRequest::decode_varint(uint32_t field_id, ProtoVarInt value) { @@ -1706,12 +1706,12 @@ void MediaPlayerSupportedFormat::encode(ProtoWriteBuffer buffer) const { buffer.encode_uint32(4, static_cast(this->purpose)); buffer.encode_uint32(5, this->sample_bytes); } -void MediaPlayerSupportedFormat::calculate_size(uint32_t &total_size) const { - ProtoSize::add_string_field(total_size, 1, this->format_ref_.size()); - ProtoSize::add_uint32_field(total_size, 1, this->sample_rate); - ProtoSize::add_uint32_field(total_size, 1, this->num_channels); - ProtoSize::add_enum_field(total_size, 1, static_cast(this->purpose)); - ProtoSize::add_uint32_field(total_size, 1, this->sample_bytes); +void MediaPlayerSupportedFormat::calculate_size(ProtoSize &size) const { + size.add_string_field(1, this->format_ref_.size()); + size.add_uint32_field(1, this->sample_rate); + size.add_uint32_field(1, this->num_channels); + size.add_enum_field(1, static_cast(this->purpose)); + size.add_uint32_field(1, this->sample_bytes); } void ListEntitiesMediaPlayerResponse::encode(ProtoWriteBuffer buffer) const { buffer.encode_string(1, this->object_id_ref_); @@ -1730,19 +1730,19 @@ void ListEntitiesMediaPlayerResponse::encode(ProtoWriteBuffer buffer) const { buffer.encode_uint32(10, this->device_id); #endif } -void ListEntitiesMediaPlayerResponse::calculate_size(uint32_t &total_size) const { - ProtoSize::add_string_field(total_size, 1, this->object_id_ref_.size()); - ProtoSize::add_fixed32_field(total_size, 1, this->key); - ProtoSize::add_string_field(total_size, 1, this->name_ref_.size()); +void ListEntitiesMediaPlayerResponse::calculate_size(ProtoSize &size) const { + size.add_string_field(1, this->object_id_ref_.size()); + size.add_fixed32_field(1, this->key); + size.add_string_field(1, this->name_ref_.size()); #ifdef USE_ENTITY_ICON - ProtoSize::add_string_field(total_size, 1, this->icon_ref_.size()); + size.add_string_field(1, this->icon_ref_.size()); #endif - ProtoSize::add_bool_field(total_size, 1, this->disabled_by_default); - ProtoSize::add_enum_field(total_size, 1, static_cast(this->entity_category)); - ProtoSize::add_bool_field(total_size, 1, this->supports_pause); - ProtoSize::add_repeated_message(total_size, 1, this->supported_formats); + size.add_bool_field(1, this->disabled_by_default); + size.add_enum_field(1, static_cast(this->entity_category)); + size.add_bool_field(1, this->supports_pause); + size.add_repeated_message(1, this->supported_formats); #ifdef USE_DEVICES - ProtoSize::add_uint32_field(total_size, 1, this->device_id); + size.add_uint32_field(1, this->device_id); #endif } void MediaPlayerStateResponse::encode(ProtoWriteBuffer buffer) const { @@ -1754,13 +1754,13 @@ void MediaPlayerStateResponse::encode(ProtoWriteBuffer buffer) const { buffer.encode_uint32(5, this->device_id); #endif } -void MediaPlayerStateResponse::calculate_size(uint32_t &total_size) const { - ProtoSize::add_fixed32_field(total_size, 1, this->key); - ProtoSize::add_enum_field(total_size, 1, static_cast(this->state)); - ProtoSize::add_float_field(total_size, 1, this->volume); - ProtoSize::add_bool_field(total_size, 1, this->muted); +void MediaPlayerStateResponse::calculate_size(ProtoSize &size) const { + size.add_fixed32_field(1, this->key); + size.add_enum_field(1, static_cast(this->state)); + size.add_float_field(1, this->volume); + size.add_bool_field(1, this->muted); #ifdef USE_DEVICES - ProtoSize::add_uint32_field(total_size, 1, this->device_id); + size.add_uint32_field(1, this->device_id); #endif } bool MediaPlayerCommandRequest::decode_varint(uint32_t field_id, ProtoVarInt value) { @@ -1834,21 +1834,19 @@ void BluetoothLERawAdvertisement::encode(ProtoWriteBuffer buffer) const { buffer.encode_uint32(3, this->address_type); buffer.encode_bytes(4, this->data, this->data_len); } -void BluetoothLERawAdvertisement::calculate_size(uint32_t &total_size) const { - ProtoSize::add_uint64_field(total_size, 1, this->address); - ProtoSize::add_sint32_field(total_size, 1, this->rssi); - ProtoSize::add_uint32_field(total_size, 1, this->address_type); - if (this->data_len != 0) { - total_size += 1 + ProtoSize::varint(static_cast(this->data_len)) + this->data_len; - } +void BluetoothLERawAdvertisement::calculate_size(ProtoSize &size) const { + size.add_uint64_field(1, this->address); + size.add_sint32_field(1, this->rssi); + size.add_uint32_field(1, this->address_type); + size.add_bytes_field(1, this->data_len); } void BluetoothLERawAdvertisementsResponse::encode(ProtoWriteBuffer buffer) const { for (auto &it : this->advertisements) { buffer.encode_message(1, it, true); } } -void BluetoothLERawAdvertisementsResponse::calculate_size(uint32_t &total_size) const { - ProtoSize::add_repeated_message(total_size, 1, this->advertisements); +void BluetoothLERawAdvertisementsResponse::calculate_size(ProtoSize &size) const { + size.add_repeated_message(1, this->advertisements); } bool BluetoothDeviceRequest::decode_varint(uint32_t field_id, ProtoVarInt value) { switch (field_id) { @@ -1875,11 +1873,11 @@ void BluetoothDeviceConnectionResponse::encode(ProtoWriteBuffer buffer) const { buffer.encode_uint32(3, this->mtu); buffer.encode_int32(4, this->error); } -void BluetoothDeviceConnectionResponse::calculate_size(uint32_t &total_size) const { - ProtoSize::add_uint64_field(total_size, 1, this->address); - ProtoSize::add_bool_field(total_size, 1, this->connected); - ProtoSize::add_uint32_field(total_size, 1, this->mtu); - ProtoSize::add_int32_field(total_size, 1, this->error); +void BluetoothDeviceConnectionResponse::calculate_size(ProtoSize &size) const { + size.add_uint64_field(1, this->address); + size.add_bool_field(1, this->connected); + size.add_uint32_field(1, this->mtu); + size.add_int32_field(1, this->error); } bool BluetoothGATTGetServicesRequest::decode_varint(uint32_t field_id, ProtoVarInt value) { switch (field_id) { @@ -1896,10 +1894,10 @@ void BluetoothGATTDescriptor::encode(ProtoWriteBuffer buffer) const { buffer.encode_uint64(1, this->uuid[1], true); buffer.encode_uint32(2, this->handle); } -void BluetoothGATTDescriptor::calculate_size(uint32_t &total_size) const { - ProtoSize::add_uint64_field_repeated(total_size, 1, this->uuid[0]); - ProtoSize::add_uint64_field_repeated(total_size, 1, this->uuid[1]); - ProtoSize::add_uint32_field(total_size, 1, this->handle); +void BluetoothGATTDescriptor::calculate_size(ProtoSize &size) const { + size.add_uint64_field_repeated(1, this->uuid[0]); + size.add_uint64_field_repeated(1, this->uuid[1]); + size.add_uint32_field(1, this->handle); } void BluetoothGATTCharacteristic::encode(ProtoWriteBuffer buffer) const { buffer.encode_uint64(1, this->uuid[0], true); @@ -1910,12 +1908,12 @@ void BluetoothGATTCharacteristic::encode(ProtoWriteBuffer buffer) const { buffer.encode_message(4, it, true); } } -void BluetoothGATTCharacteristic::calculate_size(uint32_t &total_size) const { - ProtoSize::add_uint64_field_repeated(total_size, 1, this->uuid[0]); - ProtoSize::add_uint64_field_repeated(total_size, 1, this->uuid[1]); - ProtoSize::add_uint32_field(total_size, 1, this->handle); - ProtoSize::add_uint32_field(total_size, 1, this->properties); - ProtoSize::add_repeated_message(total_size, 1, this->descriptors); +void BluetoothGATTCharacteristic::calculate_size(ProtoSize &size) const { + size.add_uint64_field_repeated(1, this->uuid[0]); + size.add_uint64_field_repeated(1, this->uuid[1]); + size.add_uint32_field(1, this->handle); + size.add_uint32_field(1, this->properties); + size.add_repeated_message(1, this->descriptors); } void BluetoothGATTService::encode(ProtoWriteBuffer buffer) const { buffer.encode_uint64(1, this->uuid[0], true); @@ -1925,25 +1923,25 @@ void BluetoothGATTService::encode(ProtoWriteBuffer buffer) const { buffer.encode_message(3, it, true); } } -void BluetoothGATTService::calculate_size(uint32_t &total_size) const { - ProtoSize::add_uint64_field_repeated(total_size, 1, this->uuid[0]); - ProtoSize::add_uint64_field_repeated(total_size, 1, this->uuid[1]); - ProtoSize::add_uint32_field(total_size, 1, this->handle); - ProtoSize::add_repeated_message(total_size, 1, this->characteristics); +void BluetoothGATTService::calculate_size(ProtoSize &size) const { + size.add_uint64_field_repeated(1, this->uuid[0]); + size.add_uint64_field_repeated(1, this->uuid[1]); + size.add_uint32_field(1, this->handle); + size.add_repeated_message(1, this->characteristics); } void BluetoothGATTGetServicesResponse::encode(ProtoWriteBuffer buffer) const { buffer.encode_uint64(1, this->address); buffer.encode_message(2, this->services[0], true); } -void BluetoothGATTGetServicesResponse::calculate_size(uint32_t &total_size) const { - ProtoSize::add_uint64_field(total_size, 1, this->address); - ProtoSize::add_message_object_repeated(total_size, 1, this->services[0]); +void BluetoothGATTGetServicesResponse::calculate_size(ProtoSize &size) const { + size.add_uint64_field(1, this->address); + size.add_message_object_repeated(1, this->services[0]); } void BluetoothGATTGetServicesDoneResponse::encode(ProtoWriteBuffer buffer) const { buffer.encode_uint64(1, this->address); } -void BluetoothGATTGetServicesDoneResponse::calculate_size(uint32_t &total_size) const { - ProtoSize::add_uint64_field(total_size, 1, this->address); +void BluetoothGATTGetServicesDoneResponse::calculate_size(ProtoSize &size) const { + size.add_uint64_field(1, this->address); } bool BluetoothGATTReadRequest::decode_varint(uint32_t field_id, ProtoVarInt value) { switch (field_id) { @@ -1963,10 +1961,10 @@ void BluetoothGATTReadResponse::encode(ProtoWriteBuffer buffer) const { buffer.encode_uint32(2, this->handle); buffer.encode_bytes(3, this->data_ptr_, this->data_len_); } -void BluetoothGATTReadResponse::calculate_size(uint32_t &total_size) const { - ProtoSize::add_uint64_field(total_size, 1, this->address); - ProtoSize::add_uint32_field(total_size, 1, this->handle); - ProtoSize::add_bytes_field(total_size, 1, this->data_len_); +void BluetoothGATTReadResponse::calculate_size(ProtoSize &size) const { + size.add_uint64_field(1, this->address); + size.add_uint32_field(1, this->handle); + size.add_bytes_field(1, this->data_len_); } bool BluetoothGATTWriteRequest::decode_varint(uint32_t field_id, ProtoVarInt value) { switch (field_id) { @@ -2051,10 +2049,10 @@ void BluetoothGATTNotifyDataResponse::encode(ProtoWriteBuffer buffer) const { buffer.encode_uint32(2, this->handle); buffer.encode_bytes(3, this->data_ptr_, this->data_len_); } -void BluetoothGATTNotifyDataResponse::calculate_size(uint32_t &total_size) const { - ProtoSize::add_uint64_field(total_size, 1, this->address); - ProtoSize::add_uint32_field(total_size, 1, this->handle); - ProtoSize::add_bytes_field(total_size, 1, this->data_len_); +void BluetoothGATTNotifyDataResponse::calculate_size(ProtoSize &size) const { + size.add_uint64_field(1, this->address); + size.add_uint32_field(1, this->handle); + size.add_bytes_field(1, this->data_len_); } void BluetoothConnectionsFreeResponse::encode(ProtoWriteBuffer buffer) const { buffer.encode_uint32(1, this->free); @@ -2063,12 +2061,12 @@ void BluetoothConnectionsFreeResponse::encode(ProtoWriteBuffer buffer) const { buffer.encode_uint64(3, it, true); } } -void BluetoothConnectionsFreeResponse::calculate_size(uint32_t &total_size) const { - ProtoSize::add_uint32_field(total_size, 1, this->free); - ProtoSize::add_uint32_field(total_size, 1, this->limit); +void BluetoothConnectionsFreeResponse::calculate_size(ProtoSize &size) const { + size.add_uint32_field(1, this->free); + size.add_uint32_field(1, this->limit); if (!this->allocated.empty()) { for (const auto &it : this->allocated) { - ProtoSize::add_uint64_field_repeated(total_size, 1, it); + size.add_uint64_field_repeated(1, it); } } } @@ -2077,64 +2075,64 @@ void BluetoothGATTErrorResponse::encode(ProtoWriteBuffer buffer) const { buffer.encode_uint32(2, this->handle); buffer.encode_int32(3, this->error); } -void BluetoothGATTErrorResponse::calculate_size(uint32_t &total_size) const { - ProtoSize::add_uint64_field(total_size, 1, this->address); - ProtoSize::add_uint32_field(total_size, 1, this->handle); - ProtoSize::add_int32_field(total_size, 1, this->error); +void BluetoothGATTErrorResponse::calculate_size(ProtoSize &size) const { + size.add_uint64_field(1, this->address); + size.add_uint32_field(1, this->handle); + size.add_int32_field(1, this->error); } void BluetoothGATTWriteResponse::encode(ProtoWriteBuffer buffer) const { buffer.encode_uint64(1, this->address); buffer.encode_uint32(2, this->handle); } -void BluetoothGATTWriteResponse::calculate_size(uint32_t &total_size) const { - ProtoSize::add_uint64_field(total_size, 1, this->address); - ProtoSize::add_uint32_field(total_size, 1, this->handle); +void BluetoothGATTWriteResponse::calculate_size(ProtoSize &size) const { + size.add_uint64_field(1, this->address); + size.add_uint32_field(1, this->handle); } void BluetoothGATTNotifyResponse::encode(ProtoWriteBuffer buffer) const { buffer.encode_uint64(1, this->address); buffer.encode_uint32(2, this->handle); } -void BluetoothGATTNotifyResponse::calculate_size(uint32_t &total_size) const { - ProtoSize::add_uint64_field(total_size, 1, this->address); - ProtoSize::add_uint32_field(total_size, 1, this->handle); +void BluetoothGATTNotifyResponse::calculate_size(ProtoSize &size) const { + size.add_uint64_field(1, this->address); + size.add_uint32_field(1, this->handle); } void BluetoothDevicePairingResponse::encode(ProtoWriteBuffer buffer) const { buffer.encode_uint64(1, this->address); buffer.encode_bool(2, this->paired); buffer.encode_int32(3, this->error); } -void BluetoothDevicePairingResponse::calculate_size(uint32_t &total_size) const { - ProtoSize::add_uint64_field(total_size, 1, this->address); - ProtoSize::add_bool_field(total_size, 1, this->paired); - ProtoSize::add_int32_field(total_size, 1, this->error); +void BluetoothDevicePairingResponse::calculate_size(ProtoSize &size) const { + size.add_uint64_field(1, this->address); + size.add_bool_field(1, this->paired); + size.add_int32_field(1, this->error); } void BluetoothDeviceUnpairingResponse::encode(ProtoWriteBuffer buffer) const { buffer.encode_uint64(1, this->address); buffer.encode_bool(2, this->success); buffer.encode_int32(3, this->error); } -void BluetoothDeviceUnpairingResponse::calculate_size(uint32_t &total_size) const { - ProtoSize::add_uint64_field(total_size, 1, this->address); - ProtoSize::add_bool_field(total_size, 1, this->success); - ProtoSize::add_int32_field(total_size, 1, this->error); +void BluetoothDeviceUnpairingResponse::calculate_size(ProtoSize &size) const { + size.add_uint64_field(1, this->address); + size.add_bool_field(1, this->success); + size.add_int32_field(1, this->error); } void BluetoothDeviceClearCacheResponse::encode(ProtoWriteBuffer buffer) const { buffer.encode_uint64(1, this->address); buffer.encode_bool(2, this->success); buffer.encode_int32(3, this->error); } -void BluetoothDeviceClearCacheResponse::calculate_size(uint32_t &total_size) const { - ProtoSize::add_uint64_field(total_size, 1, this->address); - ProtoSize::add_bool_field(total_size, 1, this->success); - ProtoSize::add_int32_field(total_size, 1, this->error); +void BluetoothDeviceClearCacheResponse::calculate_size(ProtoSize &size) const { + size.add_uint64_field(1, this->address); + size.add_bool_field(1, this->success); + size.add_int32_field(1, this->error); } void BluetoothScannerStateResponse::encode(ProtoWriteBuffer buffer) const { buffer.encode_uint32(1, static_cast(this->state)); buffer.encode_uint32(2, static_cast(this->mode)); } -void BluetoothScannerStateResponse::calculate_size(uint32_t &total_size) const { - ProtoSize::add_enum_field(total_size, 1, static_cast(this->state)); - ProtoSize::add_enum_field(total_size, 1, static_cast(this->mode)); +void BluetoothScannerStateResponse::calculate_size(ProtoSize &size) const { + size.add_enum_field(1, static_cast(this->state)); + size.add_enum_field(1, static_cast(this->mode)); } bool BluetoothScannerSetModeRequest::decode_varint(uint32_t field_id, ProtoVarInt value) { switch (field_id) { @@ -2166,10 +2164,10 @@ void VoiceAssistantAudioSettings::encode(ProtoWriteBuffer buffer) const { buffer.encode_uint32(2, this->auto_gain); buffer.encode_float(3, this->volume_multiplier); } -void VoiceAssistantAudioSettings::calculate_size(uint32_t &total_size) const { - ProtoSize::add_uint32_field(total_size, 1, this->noise_suppression_level); - ProtoSize::add_uint32_field(total_size, 1, this->auto_gain); - ProtoSize::add_float_field(total_size, 1, this->volume_multiplier); +void VoiceAssistantAudioSettings::calculate_size(ProtoSize &size) const { + size.add_uint32_field(1, this->noise_suppression_level); + size.add_uint32_field(1, this->auto_gain); + size.add_float_field(1, this->volume_multiplier); } void VoiceAssistantRequest::encode(ProtoWriteBuffer buffer) const { buffer.encode_bool(1, this->start); @@ -2178,12 +2176,12 @@ void VoiceAssistantRequest::encode(ProtoWriteBuffer buffer) const { buffer.encode_message(4, this->audio_settings); buffer.encode_string(5, this->wake_word_phrase_ref_); } -void VoiceAssistantRequest::calculate_size(uint32_t &total_size) const { - ProtoSize::add_bool_field(total_size, 1, this->start); - ProtoSize::add_string_field(total_size, 1, this->conversation_id_ref_.size()); - ProtoSize::add_uint32_field(total_size, 1, this->flags); - ProtoSize::add_message_object(total_size, 1, this->audio_settings); - ProtoSize::add_string_field(total_size, 1, this->wake_word_phrase_ref_.size()); +void VoiceAssistantRequest::calculate_size(ProtoSize &size) const { + size.add_bool_field(1, this->start); + size.add_string_field(1, this->conversation_id_ref_.size()); + size.add_uint32_field(1, this->flags); + size.add_message_object(1, this->audio_settings); + size.add_string_field(1, this->wake_word_phrase_ref_.size()); } bool VoiceAssistantResponse::decode_varint(uint32_t field_id, ProtoVarInt value) { switch (field_id) { @@ -2256,9 +2254,9 @@ void VoiceAssistantAudio::encode(ProtoWriteBuffer buffer) const { buffer.encode_bytes(1, this->data_ptr_, this->data_len_); buffer.encode_bool(2, this->end); } -void VoiceAssistantAudio::calculate_size(uint32_t &total_size) const { - ProtoSize::add_bytes_field(total_size, 1, this->data_len_); - ProtoSize::add_bool_field(total_size, 1, this->end); +void VoiceAssistantAudio::calculate_size(ProtoSize &size) const { + size.add_bytes_field(1, this->data_len_); + size.add_bool_field(1, this->end); } bool VoiceAssistantTimerEventResponse::decode_varint(uint32_t field_id, ProtoVarInt value) { switch (field_id) { @@ -2319,8 +2317,8 @@ bool VoiceAssistantAnnounceRequest::decode_length(uint32_t field_id, ProtoLength return true; } void VoiceAssistantAnnounceFinished::encode(ProtoWriteBuffer buffer) const { buffer.encode_bool(1, this->success); } -void VoiceAssistantAnnounceFinished::calculate_size(uint32_t &total_size) const { - ProtoSize::add_bool_field(total_size, 1, this->success); +} +void VoiceAssistantAnnounceFinished::calculate_size(ProtoSize &size) const { size.add_bool_field(1, this->success); } } void VoiceAssistantWakeWord::encode(ProtoWriteBuffer buffer) const { buffer.encode_string(1, this->id_ref_); @@ -2329,12 +2327,12 @@ void VoiceAssistantWakeWord::encode(ProtoWriteBuffer buffer) const { buffer.encode_string(3, it, true); } } -void VoiceAssistantWakeWord::calculate_size(uint32_t &total_size) const { - ProtoSize::add_string_field(total_size, 1, this->id_ref_.size()); - ProtoSize::add_string_field(total_size, 1, this->wake_word_ref_.size()); +void VoiceAssistantWakeWord::calculate_size(ProtoSize &size) const { + size.add_string_field(1, this->id_ref_.size()); + size.add_string_field(1, this->wake_word_ref_.size()); if (!this->trained_languages.empty()) { for (const auto &it : this->trained_languages) { - ProtoSize::add_string_field_repeated(total_size, 1, it); + size.add_string_field_repeated(1, it); } } } @@ -2347,14 +2345,14 @@ void VoiceAssistantConfigurationResponse::encode(ProtoWriteBuffer buffer) const } buffer.encode_uint32(3, this->max_active_wake_words); } -void VoiceAssistantConfigurationResponse::calculate_size(uint32_t &total_size) const { - ProtoSize::add_repeated_message(total_size, 1, this->available_wake_words); +void VoiceAssistantConfigurationResponse::calculate_size(ProtoSize &size) const { + size.add_repeated_message(1, this->available_wake_words); if (!this->active_wake_words.empty()) { for (const auto &it : this->active_wake_words) { - ProtoSize::add_string_field_repeated(total_size, 1, it); + size.add_string_field_repeated(1, it); } } - ProtoSize::add_uint32_field(total_size, 1, this->max_active_wake_words); + size.add_uint32_field(1, this->max_active_wake_words); } bool VoiceAssistantSetConfiguration::decode_length(uint32_t field_id, ProtoLengthDelimited value) { switch (field_id) { @@ -2384,20 +2382,20 @@ void ListEntitiesAlarmControlPanelResponse::encode(ProtoWriteBuffer buffer) cons buffer.encode_uint32(11, this->device_id); #endif } -void ListEntitiesAlarmControlPanelResponse::calculate_size(uint32_t &total_size) const { - ProtoSize::add_string_field(total_size, 1, this->object_id_ref_.size()); - ProtoSize::add_fixed32_field(total_size, 1, this->key); - ProtoSize::add_string_field(total_size, 1, this->name_ref_.size()); +void ListEntitiesAlarmControlPanelResponse::calculate_size(ProtoSize &size) const { + size.add_string_field(1, this->object_id_ref_.size()); + size.add_fixed32_field(1, this->key); + size.add_string_field(1, this->name_ref_.size()); #ifdef USE_ENTITY_ICON - ProtoSize::add_string_field(total_size, 1, this->icon_ref_.size()); + size.add_string_field(1, this->icon_ref_.size()); #endif - ProtoSize::add_bool_field(total_size, 1, this->disabled_by_default); - ProtoSize::add_enum_field(total_size, 1, static_cast(this->entity_category)); - ProtoSize::add_uint32_field(total_size, 1, this->supported_features); - ProtoSize::add_bool_field(total_size, 1, this->requires_code); - ProtoSize::add_bool_field(total_size, 1, this->requires_code_to_arm); + size.add_bool_field(1, this->disabled_by_default); + size.add_enum_field(1, static_cast(this->entity_category)); + size.add_uint32_field(1, this->supported_features); + size.add_bool_field(1, this->requires_code); + size.add_bool_field(1, this->requires_code_to_arm); #ifdef USE_DEVICES - ProtoSize::add_uint32_field(total_size, 1, this->device_id); + size.add_uint32_field(1, this->device_id); #endif } void AlarmControlPanelStateResponse::encode(ProtoWriteBuffer buffer) const { @@ -2407,11 +2405,11 @@ void AlarmControlPanelStateResponse::encode(ProtoWriteBuffer buffer) const { buffer.encode_uint32(3, this->device_id); #endif } -void AlarmControlPanelStateResponse::calculate_size(uint32_t &total_size) const { - ProtoSize::add_fixed32_field(total_size, 1, this->key); - ProtoSize::add_enum_field(total_size, 1, static_cast(this->state)); +void AlarmControlPanelStateResponse::calculate_size(ProtoSize &size) const { + size.add_fixed32_field(1, this->key); + size.add_enum_field(1, static_cast(this->state)); #ifdef USE_DEVICES - ProtoSize::add_uint32_field(total_size, 1, this->device_id); + size.add_uint32_field(1, this->device_id); #endif } bool AlarmControlPanelCommandRequest::decode_varint(uint32_t field_id, ProtoVarInt value) { @@ -2468,21 +2466,21 @@ void ListEntitiesTextResponse::encode(ProtoWriteBuffer buffer) const { buffer.encode_uint32(12, this->device_id); #endif } -void ListEntitiesTextResponse::calculate_size(uint32_t &total_size) const { - ProtoSize::add_string_field(total_size, 1, this->object_id_ref_.size()); - ProtoSize::add_fixed32_field(total_size, 1, this->key); - ProtoSize::add_string_field(total_size, 1, this->name_ref_.size()); +void ListEntitiesTextResponse::calculate_size(ProtoSize &size) const { + size.add_string_field(1, this->object_id_ref_.size()); + size.add_fixed32_field(1, this->key); + size.add_string_field(1, this->name_ref_.size()); #ifdef USE_ENTITY_ICON - ProtoSize::add_string_field(total_size, 1, this->icon_ref_.size()); + size.add_string_field(1, this->icon_ref_.size()); #endif - ProtoSize::add_bool_field(total_size, 1, this->disabled_by_default); - ProtoSize::add_enum_field(total_size, 1, static_cast(this->entity_category)); - ProtoSize::add_uint32_field(total_size, 1, this->min_length); - ProtoSize::add_uint32_field(total_size, 1, this->max_length); - ProtoSize::add_string_field(total_size, 1, this->pattern_ref_.size()); - ProtoSize::add_enum_field(total_size, 1, static_cast(this->mode)); + size.add_bool_field(1, this->disabled_by_default); + size.add_enum_field(1, static_cast(this->entity_category)); + size.add_uint32_field(1, this->min_length); + size.add_uint32_field(1, this->max_length); + size.add_string_field(1, this->pattern_ref_.size()); + size.add_enum_field(1, static_cast(this->mode)); #ifdef USE_DEVICES - ProtoSize::add_uint32_field(total_size, 1, this->device_id); + size.add_uint32_field(1, this->device_id); #endif } void TextStateResponse::encode(ProtoWriteBuffer buffer) const { @@ -2493,12 +2491,12 @@ void TextStateResponse::encode(ProtoWriteBuffer buffer) const { buffer.encode_uint32(4, this->device_id); #endif } -void TextStateResponse::calculate_size(uint32_t &total_size) const { - ProtoSize::add_fixed32_field(total_size, 1, this->key); - ProtoSize::add_string_field(total_size, 1, this->state_ref_.size()); - ProtoSize::add_bool_field(total_size, 1, this->missing_state); +void TextStateResponse::calculate_size(ProtoSize &size) const { + size.add_fixed32_field(1, this->key); + size.add_string_field(1, this->state_ref_.size()); + size.add_bool_field(1, this->missing_state); #ifdef USE_DEVICES - ProtoSize::add_uint32_field(total_size, 1, this->device_id); + size.add_uint32_field(1, this->device_id); #endif } bool TextCommandRequest::decode_varint(uint32_t field_id, ProtoVarInt value) { @@ -2548,17 +2546,17 @@ void ListEntitiesDateResponse::encode(ProtoWriteBuffer buffer) const { buffer.encode_uint32(8, this->device_id); #endif } -void ListEntitiesDateResponse::calculate_size(uint32_t &total_size) const { - ProtoSize::add_string_field(total_size, 1, this->object_id_ref_.size()); - ProtoSize::add_fixed32_field(total_size, 1, this->key); - ProtoSize::add_string_field(total_size, 1, this->name_ref_.size()); +void ListEntitiesDateResponse::calculate_size(ProtoSize &size) const { + size.add_string_field(1, this->object_id_ref_.size()); + size.add_fixed32_field(1, this->key); + size.add_string_field(1, this->name_ref_.size()); #ifdef USE_ENTITY_ICON - ProtoSize::add_string_field(total_size, 1, this->icon_ref_.size()); + size.add_string_field(1, this->icon_ref_.size()); #endif - ProtoSize::add_bool_field(total_size, 1, this->disabled_by_default); - ProtoSize::add_enum_field(total_size, 1, static_cast(this->entity_category)); + size.add_bool_field(1, this->disabled_by_default); + size.add_enum_field(1, static_cast(this->entity_category)); #ifdef USE_DEVICES - ProtoSize::add_uint32_field(total_size, 1, this->device_id); + size.add_uint32_field(1, this->device_id); #endif } void DateStateResponse::encode(ProtoWriteBuffer buffer) const { @@ -2571,14 +2569,14 @@ void DateStateResponse::encode(ProtoWriteBuffer buffer) const { buffer.encode_uint32(6, this->device_id); #endif } -void DateStateResponse::calculate_size(uint32_t &total_size) const { - ProtoSize::add_fixed32_field(total_size, 1, this->key); - ProtoSize::add_bool_field(total_size, 1, this->missing_state); - ProtoSize::add_uint32_field(total_size, 1, this->year); - ProtoSize::add_uint32_field(total_size, 1, this->month); - ProtoSize::add_uint32_field(total_size, 1, this->day); +void DateStateResponse::calculate_size(ProtoSize &size) const { + size.add_fixed32_field(1, this->key); + size.add_bool_field(1, this->missing_state); + size.add_uint32_field(1, this->year); + size.add_uint32_field(1, this->month); + size.add_uint32_field(1, this->day); #ifdef USE_DEVICES - ProtoSize::add_uint32_field(total_size, 1, this->device_id); + size.add_uint32_field(1, this->device_id); #endif } bool DateCommandRequest::decode_varint(uint32_t field_id, ProtoVarInt value) { @@ -2627,17 +2625,17 @@ void ListEntitiesTimeResponse::encode(ProtoWriteBuffer buffer) const { buffer.encode_uint32(8, this->device_id); #endif } -void ListEntitiesTimeResponse::calculate_size(uint32_t &total_size) const { - ProtoSize::add_string_field(total_size, 1, this->object_id_ref_.size()); - ProtoSize::add_fixed32_field(total_size, 1, this->key); - ProtoSize::add_string_field(total_size, 1, this->name_ref_.size()); +void ListEntitiesTimeResponse::calculate_size(ProtoSize &size) const { + size.add_string_field(1, this->object_id_ref_.size()); + size.add_fixed32_field(1, this->key); + size.add_string_field(1, this->name_ref_.size()); #ifdef USE_ENTITY_ICON - ProtoSize::add_string_field(total_size, 1, this->icon_ref_.size()); + size.add_string_field(1, this->icon_ref_.size()); #endif - ProtoSize::add_bool_field(total_size, 1, this->disabled_by_default); - ProtoSize::add_enum_field(total_size, 1, static_cast(this->entity_category)); + size.add_bool_field(1, this->disabled_by_default); + size.add_enum_field(1, static_cast(this->entity_category)); #ifdef USE_DEVICES - ProtoSize::add_uint32_field(total_size, 1, this->device_id); + size.add_uint32_field(1, this->device_id); #endif } void TimeStateResponse::encode(ProtoWriteBuffer buffer) const { @@ -2650,14 +2648,14 @@ void TimeStateResponse::encode(ProtoWriteBuffer buffer) const { buffer.encode_uint32(6, this->device_id); #endif } -void TimeStateResponse::calculate_size(uint32_t &total_size) const { - ProtoSize::add_fixed32_field(total_size, 1, this->key); - ProtoSize::add_bool_field(total_size, 1, this->missing_state); - ProtoSize::add_uint32_field(total_size, 1, this->hour); - ProtoSize::add_uint32_field(total_size, 1, this->minute); - ProtoSize::add_uint32_field(total_size, 1, this->second); +void TimeStateResponse::calculate_size(ProtoSize &size) const { + size.add_fixed32_field(1, this->key); + size.add_bool_field(1, this->missing_state); + size.add_uint32_field(1, this->hour); + size.add_uint32_field(1, this->minute); + size.add_uint32_field(1, this->second); #ifdef USE_DEVICES - ProtoSize::add_uint32_field(total_size, 1, this->device_id); + size.add_uint32_field(1, this->device_id); #endif } bool TimeCommandRequest::decode_varint(uint32_t field_id, ProtoVarInt value) { @@ -2710,23 +2708,23 @@ void ListEntitiesEventResponse::encode(ProtoWriteBuffer buffer) const { buffer.encode_uint32(10, this->device_id); #endif } -void ListEntitiesEventResponse::calculate_size(uint32_t &total_size) const { - ProtoSize::add_string_field(total_size, 1, this->object_id_ref_.size()); - ProtoSize::add_fixed32_field(total_size, 1, this->key); - ProtoSize::add_string_field(total_size, 1, this->name_ref_.size()); +void ListEntitiesEventResponse::calculate_size(ProtoSize &size) const { + size.add_string_field(1, this->object_id_ref_.size()); + size.add_fixed32_field(1, this->key); + size.add_string_field(1, this->name_ref_.size()); #ifdef USE_ENTITY_ICON - ProtoSize::add_string_field(total_size, 1, this->icon_ref_.size()); + size.add_string_field(1, this->icon_ref_.size()); #endif - ProtoSize::add_bool_field(total_size, 1, this->disabled_by_default); - ProtoSize::add_enum_field(total_size, 1, static_cast(this->entity_category)); - ProtoSize::add_string_field(total_size, 1, this->device_class_ref_.size()); + size.add_bool_field(1, this->disabled_by_default); + size.add_enum_field(1, static_cast(this->entity_category)); + size.add_string_field(1, this->device_class_ref_.size()); if (!this->event_types.empty()) { for (const auto &it : this->event_types) { - ProtoSize::add_string_field_repeated(total_size, 1, it); + size.add_string_field_repeated(1, it); } } #ifdef USE_DEVICES - ProtoSize::add_uint32_field(total_size, 1, this->device_id); + size.add_uint32_field(1, this->device_id); #endif } void EventResponse::encode(ProtoWriteBuffer buffer) const { @@ -2736,11 +2734,11 @@ void EventResponse::encode(ProtoWriteBuffer buffer) const { buffer.encode_uint32(3, this->device_id); #endif } -void EventResponse::calculate_size(uint32_t &total_size) const { - ProtoSize::add_fixed32_field(total_size, 1, this->key); - ProtoSize::add_string_field(total_size, 1, this->event_type_ref_.size()); +void EventResponse::calculate_size(ProtoSize &size) const { + size.add_fixed32_field(1, this->key); + size.add_string_field(1, this->event_type_ref_.size()); #ifdef USE_DEVICES - ProtoSize::add_uint32_field(total_size, 1, this->device_id); + size.add_uint32_field(1, this->device_id); #endif } #endif @@ -2762,21 +2760,21 @@ void ListEntitiesValveResponse::encode(ProtoWriteBuffer buffer) const { buffer.encode_uint32(12, this->device_id); #endif } -void ListEntitiesValveResponse::calculate_size(uint32_t &total_size) const { - ProtoSize::add_string_field(total_size, 1, this->object_id_ref_.size()); - ProtoSize::add_fixed32_field(total_size, 1, this->key); - ProtoSize::add_string_field(total_size, 1, this->name_ref_.size()); +void ListEntitiesValveResponse::calculate_size(ProtoSize &size) const { + size.add_string_field(1, this->object_id_ref_.size()); + size.add_fixed32_field(1, this->key); + size.add_string_field(1, this->name_ref_.size()); #ifdef USE_ENTITY_ICON - ProtoSize::add_string_field(total_size, 1, this->icon_ref_.size()); + size.add_string_field(1, this->icon_ref_.size()); #endif - ProtoSize::add_bool_field(total_size, 1, this->disabled_by_default); - ProtoSize::add_enum_field(total_size, 1, static_cast(this->entity_category)); - ProtoSize::add_string_field(total_size, 1, this->device_class_ref_.size()); - ProtoSize::add_bool_field(total_size, 1, this->assumed_state); - ProtoSize::add_bool_field(total_size, 1, this->supports_position); - ProtoSize::add_bool_field(total_size, 1, this->supports_stop); + size.add_bool_field(1, this->disabled_by_default); + size.add_enum_field(1, static_cast(this->entity_category)); + size.add_string_field(1, this->device_class_ref_.size()); + size.add_bool_field(1, this->assumed_state); + size.add_bool_field(1, this->supports_position); + size.add_bool_field(1, this->supports_stop); #ifdef USE_DEVICES - ProtoSize::add_uint32_field(total_size, 1, this->device_id); + size.add_uint32_field(1, this->device_id); #endif } void ValveStateResponse::encode(ProtoWriteBuffer buffer) const { @@ -2787,12 +2785,12 @@ void ValveStateResponse::encode(ProtoWriteBuffer buffer) const { buffer.encode_uint32(4, this->device_id); #endif } -void ValveStateResponse::calculate_size(uint32_t &total_size) const { - ProtoSize::add_fixed32_field(total_size, 1, this->key); - ProtoSize::add_float_field(total_size, 1, this->position); - ProtoSize::add_enum_field(total_size, 1, static_cast(this->current_operation)); +void ValveStateResponse::calculate_size(ProtoSize &size) const { + size.add_fixed32_field(1, this->key); + size.add_float_field(1, this->position); + size.add_enum_field(1, static_cast(this->current_operation)); #ifdef USE_DEVICES - ProtoSize::add_uint32_field(total_size, 1, this->device_id); + size.add_uint32_field(1, this->device_id); #endif } bool ValveCommandRequest::decode_varint(uint32_t field_id, ProtoVarInt value) { @@ -2841,17 +2839,17 @@ void ListEntitiesDateTimeResponse::encode(ProtoWriteBuffer buffer) const { buffer.encode_uint32(8, this->device_id); #endif } -void ListEntitiesDateTimeResponse::calculate_size(uint32_t &total_size) const { - ProtoSize::add_string_field(total_size, 1, this->object_id_ref_.size()); - ProtoSize::add_fixed32_field(total_size, 1, this->key); - ProtoSize::add_string_field(total_size, 1, this->name_ref_.size()); +void ListEntitiesDateTimeResponse::calculate_size(ProtoSize &size) const { + size.add_string_field(1, this->object_id_ref_.size()); + size.add_fixed32_field(1, this->key); + size.add_string_field(1, this->name_ref_.size()); #ifdef USE_ENTITY_ICON - ProtoSize::add_string_field(total_size, 1, this->icon_ref_.size()); + size.add_string_field(1, this->icon_ref_.size()); #endif - ProtoSize::add_bool_field(total_size, 1, this->disabled_by_default); - ProtoSize::add_enum_field(total_size, 1, static_cast(this->entity_category)); + size.add_bool_field(1, this->disabled_by_default); + size.add_enum_field(1, static_cast(this->entity_category)); #ifdef USE_DEVICES - ProtoSize::add_uint32_field(total_size, 1, this->device_id); + size.add_uint32_field(1, this->device_id); #endif } void DateTimeStateResponse::encode(ProtoWriteBuffer buffer) const { @@ -2862,12 +2860,12 @@ void DateTimeStateResponse::encode(ProtoWriteBuffer buffer) const { buffer.encode_uint32(4, this->device_id); #endif } -void DateTimeStateResponse::calculate_size(uint32_t &total_size) const { - ProtoSize::add_fixed32_field(total_size, 1, this->key); - ProtoSize::add_bool_field(total_size, 1, this->missing_state); - ProtoSize::add_fixed32_field(total_size, 1, this->epoch_seconds); +void DateTimeStateResponse::calculate_size(ProtoSize &size) const { + size.add_fixed32_field(1, this->key); + size.add_bool_field(1, this->missing_state); + size.add_fixed32_field(1, this->epoch_seconds); #ifdef USE_DEVICES - ProtoSize::add_uint32_field(total_size, 1, this->device_id); + size.add_uint32_field(1, this->device_id); #endif } bool DateTimeCommandRequest::decode_varint(uint32_t field_id, ProtoVarInt value) { @@ -2911,18 +2909,18 @@ void ListEntitiesUpdateResponse::encode(ProtoWriteBuffer buffer) const { buffer.encode_uint32(9, this->device_id); #endif } -void ListEntitiesUpdateResponse::calculate_size(uint32_t &total_size) const { - ProtoSize::add_string_field(total_size, 1, this->object_id_ref_.size()); - ProtoSize::add_fixed32_field(total_size, 1, this->key); - ProtoSize::add_string_field(total_size, 1, this->name_ref_.size()); +void ListEntitiesUpdateResponse::calculate_size(ProtoSize &size) const { + size.add_string_field(1, this->object_id_ref_.size()); + size.add_fixed32_field(1, this->key); + size.add_string_field(1, this->name_ref_.size()); #ifdef USE_ENTITY_ICON - ProtoSize::add_string_field(total_size, 1, this->icon_ref_.size()); + size.add_string_field(1, this->icon_ref_.size()); #endif - ProtoSize::add_bool_field(total_size, 1, this->disabled_by_default); - ProtoSize::add_enum_field(total_size, 1, static_cast(this->entity_category)); - ProtoSize::add_string_field(total_size, 1, this->device_class_ref_.size()); + size.add_bool_field(1, this->disabled_by_default); + size.add_enum_field(1, static_cast(this->entity_category)); + size.add_string_field(1, this->device_class_ref_.size()); #ifdef USE_DEVICES - ProtoSize::add_uint32_field(total_size, 1, this->device_id); + size.add_uint32_field(1, this->device_id); #endif } void UpdateStateResponse::encode(ProtoWriteBuffer buffer) const { @@ -2940,19 +2938,19 @@ void UpdateStateResponse::encode(ProtoWriteBuffer buffer) const { buffer.encode_uint32(11, this->device_id); #endif } -void UpdateStateResponse::calculate_size(uint32_t &total_size) const { - ProtoSize::add_fixed32_field(total_size, 1, this->key); - ProtoSize::add_bool_field(total_size, 1, this->missing_state); - ProtoSize::add_bool_field(total_size, 1, this->in_progress); - ProtoSize::add_bool_field(total_size, 1, this->has_progress); - ProtoSize::add_float_field(total_size, 1, this->progress); - ProtoSize::add_string_field(total_size, 1, this->current_version_ref_.size()); - ProtoSize::add_string_field(total_size, 1, this->latest_version_ref_.size()); - ProtoSize::add_string_field(total_size, 1, this->title_ref_.size()); - ProtoSize::add_string_field(total_size, 1, this->release_summary_ref_.size()); - ProtoSize::add_string_field(total_size, 1, this->release_url_ref_.size()); +void UpdateStateResponse::calculate_size(ProtoSize &size) const { + size.add_fixed32_field(1, this->key); + size.add_bool_field(1, this->missing_state); + size.add_bool_field(1, this->in_progress); + size.add_bool_field(1, this->has_progress); + size.add_float_field(1, this->progress); + size.add_string_field(1, this->current_version_ref_.size()); + size.add_string_field(1, this->latest_version_ref_.size()); + size.add_string_field(1, this->title_ref_.size()); + size.add_string_field(1, this->release_summary_ref_.size()); + size.add_string_field(1, this->release_url_ref_.size()); #ifdef USE_DEVICES - ProtoSize::add_uint32_field(total_size, 1, this->device_id); + size.add_uint32_field(1, this->device_id); #endif } bool UpdateCommandRequest::decode_varint(uint32_t field_id, ProtoVarInt value) { diff --git a/esphome/components/api/api_pb2.h b/esphome/components/api/api_pb2.h index b7d8945e8e..f204acdebe 100644 --- a/esphome/components/api/api_pb2.h +++ b/esphome/components/api/api_pb2.h @@ -340,7 +340,7 @@ class HelloResponse : public ProtoMessage { StringRef name_ref_{}; void set_name(const StringRef &ref) { this->name_ref_ = ref; } void encode(ProtoWriteBuffer buffer) const override; - void calculate_size(uint32_t &total_size) const override; + void calculate_size(ProtoSize &size) const override; #ifdef HAS_PROTO_MESSAGE_DUMP void dump_to(std::string &out) const override; #endif @@ -371,7 +371,7 @@ class ConnectResponse : public ProtoMessage { #endif bool invalid_password{false}; void encode(ProtoWriteBuffer buffer) const override; - void calculate_size(uint32_t &total_size) const override; + void calculate_size(ProtoSize &size) const override; #ifdef HAS_PROTO_MESSAGE_DUMP void dump_to(std::string &out) const override; #endif @@ -450,7 +450,7 @@ class AreaInfo : public ProtoMessage { StringRef name_ref_{}; void set_name(const StringRef &ref) { this->name_ref_ = ref; } void encode(ProtoWriteBuffer buffer) const override; - void calculate_size(uint32_t &total_size) const override; + void calculate_size(ProtoSize &size) const override; #ifdef HAS_PROTO_MESSAGE_DUMP void dump_to(std::string &out) const override; #endif @@ -466,7 +466,7 @@ class DeviceInfo : public ProtoMessage { void set_name(const StringRef &ref) { this->name_ref_ = ref; } uint32_t area_id{0}; void encode(ProtoWriteBuffer buffer) const override; - void calculate_size(uint32_t &total_size) const override; + void calculate_size(ProtoSize &size) const override; #ifdef HAS_PROTO_MESSAGE_DUMP void dump_to(std::string &out) const override; #endif @@ -539,7 +539,7 @@ class DeviceInfoResponse : public ProtoMessage { AreaInfo area{}; #endif void encode(ProtoWriteBuffer buffer) const override; - void calculate_size(uint32_t &total_size) const override; + void calculate_size(ProtoSize &size) const override; #ifdef HAS_PROTO_MESSAGE_DUMP void dump_to(std::string &out) const override; #endif @@ -597,7 +597,7 @@ class ListEntitiesBinarySensorResponse : public InfoResponseProtoMessage { void set_device_class(const StringRef &ref) { this->device_class_ref_ = ref; } bool is_status_binary_sensor{false}; void encode(ProtoWriteBuffer buffer) const override; - void calculate_size(uint32_t &total_size) const override; + void calculate_size(ProtoSize &size) const override; #ifdef HAS_PROTO_MESSAGE_DUMP void dump_to(std::string &out) const override; #endif @@ -614,7 +614,7 @@ class BinarySensorStateResponse : public StateResponseProtoMessage { bool state{false}; bool missing_state{false}; void encode(ProtoWriteBuffer buffer) const override; - void calculate_size(uint32_t &total_size) const override; + void calculate_size(ProtoSize &size) const override; #ifdef HAS_PROTO_MESSAGE_DUMP void dump_to(std::string &out) const override; #endif @@ -637,7 +637,7 @@ class ListEntitiesCoverResponse : public InfoResponseProtoMessage { void set_device_class(const StringRef &ref) { this->device_class_ref_ = ref; } bool supports_stop{false}; void encode(ProtoWriteBuffer buffer) const override; - void calculate_size(uint32_t &total_size) const override; + void calculate_size(ProtoSize &size) const override; #ifdef HAS_PROTO_MESSAGE_DUMP void dump_to(std::string &out) const override; #endif @@ -655,7 +655,7 @@ class CoverStateResponse : public StateResponseProtoMessage { float tilt{0.0f}; enums::CoverOperation current_operation{}; void encode(ProtoWriteBuffer buffer) const override; - void calculate_size(uint32_t &total_size) const override; + void calculate_size(ProtoSize &size) const override; #ifdef HAS_PROTO_MESSAGE_DUMP void dump_to(std::string &out) const override; #endif @@ -697,7 +697,7 @@ class ListEntitiesFanResponse : public InfoResponseProtoMessage { int32_t supported_speed_count{0}; std::vector supported_preset_modes{}; void encode(ProtoWriteBuffer buffer) const override; - void calculate_size(uint32_t &total_size) const override; + void calculate_size(ProtoSize &size) const override; #ifdef HAS_PROTO_MESSAGE_DUMP void dump_to(std::string &out) const override; #endif @@ -718,7 +718,7 @@ class FanStateResponse : public StateResponseProtoMessage { StringRef preset_mode_ref_{}; void set_preset_mode(const StringRef &ref) { this->preset_mode_ref_ = ref; } void encode(ProtoWriteBuffer buffer) const override; - void calculate_size(uint32_t &total_size) const override; + void calculate_size(ProtoSize &size) const override; #ifdef HAS_PROTO_MESSAGE_DUMP void dump_to(std::string &out) const override; #endif @@ -765,7 +765,7 @@ class ListEntitiesLightResponse : public InfoResponseProtoMessage { float max_mireds{0.0f}; std::vector effects{}; void encode(ProtoWriteBuffer buffer) const override; - void calculate_size(uint32_t &total_size) const override; + void calculate_size(ProtoSize &size) const override; #ifdef HAS_PROTO_MESSAGE_DUMP void dump_to(std::string &out) const override; #endif @@ -793,7 +793,7 @@ class LightStateResponse : public StateResponseProtoMessage { StringRef effect_ref_{}; void set_effect(const StringRef &ref) { this->effect_ref_ = ref; } void encode(ProtoWriteBuffer buffer) const override; - void calculate_size(uint32_t &total_size) const override; + void calculate_size(ProtoSize &size) const override; #ifdef HAS_PROTO_MESSAGE_DUMP void dump_to(std::string &out) const override; #endif @@ -859,7 +859,7 @@ class ListEntitiesSensorResponse : public InfoResponseProtoMessage { void set_device_class(const StringRef &ref) { this->device_class_ref_ = ref; } enums::SensorStateClass state_class{}; void encode(ProtoWriteBuffer buffer) const override; - void calculate_size(uint32_t &total_size) const override; + void calculate_size(ProtoSize &size) const override; #ifdef HAS_PROTO_MESSAGE_DUMP void dump_to(std::string &out) const override; #endif @@ -876,7 +876,7 @@ class SensorStateResponse : public StateResponseProtoMessage { float state{0.0f}; bool missing_state{false}; void encode(ProtoWriteBuffer buffer) const override; - void calculate_size(uint32_t &total_size) const override; + void calculate_size(ProtoSize &size) const override; #ifdef HAS_PROTO_MESSAGE_DUMP void dump_to(std::string &out) const override; #endif @@ -896,7 +896,7 @@ class ListEntitiesSwitchResponse : public InfoResponseProtoMessage { StringRef device_class_ref_{}; void set_device_class(const StringRef &ref) { this->device_class_ref_ = ref; } void encode(ProtoWriteBuffer buffer) const override; - void calculate_size(uint32_t &total_size) const override; + void calculate_size(ProtoSize &size) const override; #ifdef HAS_PROTO_MESSAGE_DUMP void dump_to(std::string &out) const override; #endif @@ -912,7 +912,7 @@ class SwitchStateResponse : public StateResponseProtoMessage { #endif bool state{false}; void encode(ProtoWriteBuffer buffer) const override; - void calculate_size(uint32_t &total_size) const override; + void calculate_size(ProtoSize &size) const override; #ifdef HAS_PROTO_MESSAGE_DUMP void dump_to(std::string &out) const override; #endif @@ -947,7 +947,7 @@ class ListEntitiesTextSensorResponse : public InfoResponseProtoMessage { StringRef device_class_ref_{}; void set_device_class(const StringRef &ref) { this->device_class_ref_ = ref; } void encode(ProtoWriteBuffer buffer) const override; - void calculate_size(uint32_t &total_size) const override; + void calculate_size(ProtoSize &size) const override; #ifdef HAS_PROTO_MESSAGE_DUMP void dump_to(std::string &out) const override; #endif @@ -965,7 +965,7 @@ class TextSensorStateResponse : public StateResponseProtoMessage { void set_state(const StringRef &ref) { this->state_ref_ = ref; } bool missing_state{false}; void encode(ProtoWriteBuffer buffer) const override; - void calculate_size(uint32_t &total_size) const override; + void calculate_size(ProtoSize &size) const override; #ifdef HAS_PROTO_MESSAGE_DUMP void dump_to(std::string &out) const override; #endif @@ -1004,7 +1004,7 @@ class SubscribeLogsResponse : public ProtoMessage { this->message_len_ = len; } void encode(ProtoWriteBuffer buffer) const override; - void calculate_size(uint32_t &total_size) const override; + void calculate_size(ProtoSize &size) const override; #ifdef HAS_PROTO_MESSAGE_DUMP void dump_to(std::string &out) const override; #endif @@ -1036,7 +1036,7 @@ class NoiseEncryptionSetKeyResponse : public ProtoMessage { #endif bool success{false}; void encode(ProtoWriteBuffer buffer) const override; - void calculate_size(uint32_t &total_size) const override; + void calculate_size(ProtoSize &size) const override; #ifdef HAS_PROTO_MESSAGE_DUMP void dump_to(std::string &out) const override; #endif @@ -1064,7 +1064,7 @@ class HomeassistantServiceMap : public ProtoMessage { StringRef value_ref_{}; void set_value(const StringRef &ref) { this->value_ref_ = ref; } void encode(ProtoWriteBuffer buffer) const override; - void calculate_size(uint32_t &total_size) const override; + void calculate_size(ProtoSize &size) const override; #ifdef HAS_PROTO_MESSAGE_DUMP void dump_to(std::string &out) const override; #endif @@ -1085,7 +1085,7 @@ class HomeassistantServiceResponse : public ProtoMessage { std::vector variables{}; bool is_event{false}; void encode(ProtoWriteBuffer buffer) const override; - void calculate_size(uint32_t &total_size) const override; + void calculate_size(ProtoSize &size) const override; #ifdef HAS_PROTO_MESSAGE_DUMP void dump_to(std::string &out) const override; #endif @@ -1119,7 +1119,7 @@ class SubscribeHomeAssistantStateResponse : public ProtoMessage { void set_attribute(const StringRef &ref) { this->attribute_ref_ = ref; } bool once{false}; void encode(ProtoWriteBuffer buffer) const override; - void calculate_size(uint32_t &total_size) const override; + void calculate_size(ProtoSize &size) const override; #ifdef HAS_PROTO_MESSAGE_DUMP void dump_to(std::string &out) const override; #endif @@ -1166,7 +1166,7 @@ class GetTimeResponse : public ProtoDecodableMessage { #endif uint32_t epoch_seconds{0}; void encode(ProtoWriteBuffer buffer) const override; - void calculate_size(uint32_t &total_size) const override; + void calculate_size(ProtoSize &size) const override; #ifdef HAS_PROTO_MESSAGE_DUMP void dump_to(std::string &out) const override; #endif @@ -1181,7 +1181,7 @@ class ListEntitiesServicesArgument : public ProtoMessage { void set_name(const StringRef &ref) { this->name_ref_ = ref; } enums::ServiceArgType type{}; void encode(ProtoWriteBuffer buffer) const override; - void calculate_size(uint32_t &total_size) const override; + void calculate_size(ProtoSize &size) const override; #ifdef HAS_PROTO_MESSAGE_DUMP void dump_to(std::string &out) const override; #endif @@ -1200,7 +1200,7 @@ class ListEntitiesServicesResponse : public ProtoMessage { uint32_t key{0}; std::vector args{}; void encode(ProtoWriteBuffer buffer) const override; - void calculate_size(uint32_t &total_size) const override; + void calculate_size(ProtoSize &size) const override; #ifdef HAS_PROTO_MESSAGE_DUMP void dump_to(std::string &out) const override; #endif @@ -1254,7 +1254,7 @@ class ListEntitiesCameraResponse : public InfoResponseProtoMessage { const char *message_name() const override { return "list_entities_camera_response"; } #endif void encode(ProtoWriteBuffer buffer) const override; - void calculate_size(uint32_t &total_size) const override; + void calculate_size(ProtoSize &size) const override; #ifdef HAS_PROTO_MESSAGE_DUMP void dump_to(std::string &out) const override; #endif @@ -1276,7 +1276,7 @@ class CameraImageResponse : public StateResponseProtoMessage { } bool done{false}; void encode(ProtoWriteBuffer buffer) const override; - void calculate_size(uint32_t &total_size) const override; + void calculate_size(ProtoSize &size) const override; #ifdef HAS_PROTO_MESSAGE_DUMP void dump_to(std::string &out) const override; #endif @@ -1326,7 +1326,7 @@ class ListEntitiesClimateResponse : public InfoResponseProtoMessage { float visual_min_humidity{0.0f}; float visual_max_humidity{0.0f}; void encode(ProtoWriteBuffer buffer) const override; - void calculate_size(uint32_t &total_size) const override; + void calculate_size(ProtoSize &size) const override; #ifdef HAS_PROTO_MESSAGE_DUMP void dump_to(std::string &out) const override; #endif @@ -1356,7 +1356,7 @@ class ClimateStateResponse : public StateResponseProtoMessage { float current_humidity{0.0f}; float target_humidity{0.0f}; void encode(ProtoWriteBuffer buffer) const override; - void calculate_size(uint32_t &total_size) const override; + void calculate_size(ProtoSize &size) const override; #ifdef HAS_PROTO_MESSAGE_DUMP void dump_to(std::string &out) const override; #endif @@ -1417,7 +1417,7 @@ class ListEntitiesNumberResponse : public InfoResponseProtoMessage { StringRef device_class_ref_{}; void set_device_class(const StringRef &ref) { this->device_class_ref_ = ref; } void encode(ProtoWriteBuffer buffer) const override; - void calculate_size(uint32_t &total_size) const override; + void calculate_size(ProtoSize &size) const override; #ifdef HAS_PROTO_MESSAGE_DUMP void dump_to(std::string &out) const override; #endif @@ -1434,7 +1434,7 @@ class NumberStateResponse : public StateResponseProtoMessage { float state{0.0f}; bool missing_state{false}; void encode(ProtoWriteBuffer buffer) const override; - void calculate_size(uint32_t &total_size) const override; + void calculate_size(ProtoSize &size) const override; #ifdef HAS_PROTO_MESSAGE_DUMP void dump_to(std::string &out) const override; #endif @@ -1468,7 +1468,7 @@ class ListEntitiesSelectResponse : public InfoResponseProtoMessage { #endif std::vector options{}; void encode(ProtoWriteBuffer buffer) const override; - void calculate_size(uint32_t &total_size) const override; + void calculate_size(ProtoSize &size) const override; #ifdef HAS_PROTO_MESSAGE_DUMP void dump_to(std::string &out) const override; #endif @@ -1486,7 +1486,7 @@ class SelectStateResponse : public StateResponseProtoMessage { void set_state(const StringRef &ref) { this->state_ref_ = ref; } bool missing_state{false}; void encode(ProtoWriteBuffer buffer) const override; - void calculate_size(uint32_t &total_size) const override; + void calculate_size(ProtoSize &size) const override; #ifdef HAS_PROTO_MESSAGE_DUMP void dump_to(std::string &out) const override; #endif @@ -1523,7 +1523,7 @@ class ListEntitiesSirenResponse : public InfoResponseProtoMessage { bool supports_duration{false}; bool supports_volume{false}; void encode(ProtoWriteBuffer buffer) const override; - void calculate_size(uint32_t &total_size) const override; + void calculate_size(ProtoSize &size) const override; #ifdef HAS_PROTO_MESSAGE_DUMP void dump_to(std::string &out) const override; #endif @@ -1539,7 +1539,7 @@ class SirenStateResponse : public StateResponseProtoMessage { #endif bool state{false}; void encode(ProtoWriteBuffer buffer) const override; - void calculate_size(uint32_t &total_size) const override; + void calculate_size(ProtoSize &size) const override; #ifdef HAS_PROTO_MESSAGE_DUMP void dump_to(std::string &out) const override; #endif @@ -1585,7 +1585,7 @@ class ListEntitiesLockResponse : public InfoResponseProtoMessage { StringRef code_format_ref_{}; void set_code_format(const StringRef &ref) { this->code_format_ref_ = ref; } void encode(ProtoWriteBuffer buffer) const override; - void calculate_size(uint32_t &total_size) const override; + void calculate_size(ProtoSize &size) const override; #ifdef HAS_PROTO_MESSAGE_DUMP void dump_to(std::string &out) const override; #endif @@ -1601,7 +1601,7 @@ class LockStateResponse : public StateResponseProtoMessage { #endif enums::LockState state{}; void encode(ProtoWriteBuffer buffer) const override; - void calculate_size(uint32_t &total_size) const override; + void calculate_size(ProtoSize &size) const override; #ifdef HAS_PROTO_MESSAGE_DUMP void dump_to(std::string &out) const override; #endif @@ -1639,7 +1639,7 @@ class ListEntitiesButtonResponse : public InfoResponseProtoMessage { StringRef device_class_ref_{}; void set_device_class(const StringRef &ref) { this->device_class_ref_ = ref; } void encode(ProtoWriteBuffer buffer) const override; - void calculate_size(uint32_t &total_size) const override; + void calculate_size(ProtoSize &size) const override; #ifdef HAS_PROTO_MESSAGE_DUMP void dump_to(std::string &out) const override; #endif @@ -1672,7 +1672,7 @@ class MediaPlayerSupportedFormat : public ProtoMessage { enums::MediaPlayerFormatPurpose purpose{}; uint32_t sample_bytes{0}; void encode(ProtoWriteBuffer buffer) const override; - void calculate_size(uint32_t &total_size) const override; + void calculate_size(ProtoSize &size) const override; #ifdef HAS_PROTO_MESSAGE_DUMP void dump_to(std::string &out) const override; #endif @@ -1689,7 +1689,7 @@ class ListEntitiesMediaPlayerResponse : public InfoResponseProtoMessage { bool supports_pause{false}; std::vector supported_formats{}; void encode(ProtoWriteBuffer buffer) const override; - void calculate_size(uint32_t &total_size) const override; + void calculate_size(ProtoSize &size) const override; #ifdef HAS_PROTO_MESSAGE_DUMP void dump_to(std::string &out) const override; #endif @@ -1707,7 +1707,7 @@ class MediaPlayerStateResponse : public StateResponseProtoMessage { float volume{0.0f}; bool muted{false}; void encode(ProtoWriteBuffer buffer) const override; - void calculate_size(uint32_t &total_size) const override; + void calculate_size(ProtoSize &size) const override; #ifdef HAS_PROTO_MESSAGE_DUMP void dump_to(std::string &out) const override; #endif @@ -1763,7 +1763,7 @@ class BluetoothLERawAdvertisement : public ProtoMessage { uint8_t data[62]{}; uint8_t data_len{0}; void encode(ProtoWriteBuffer buffer) const override; - void calculate_size(uint32_t &total_size) const override; + void calculate_size(ProtoSize &size) const override; #ifdef HAS_PROTO_MESSAGE_DUMP void dump_to(std::string &out) const override; #endif @@ -1779,7 +1779,7 @@ class BluetoothLERawAdvertisementsResponse : public ProtoMessage { #endif std::vector advertisements{}; void encode(ProtoWriteBuffer buffer) const override; - void calculate_size(uint32_t &total_size) const override; + void calculate_size(ProtoSize &size) const override; #ifdef HAS_PROTO_MESSAGE_DUMP void dump_to(std::string &out) const override; #endif @@ -1816,7 +1816,7 @@ class BluetoothDeviceConnectionResponse : public ProtoMessage { uint32_t mtu{0}; int32_t error{0}; void encode(ProtoWriteBuffer buffer) const override; - void calculate_size(uint32_t &total_size) const override; + void calculate_size(ProtoSize &size) const override; #ifdef HAS_PROTO_MESSAGE_DUMP void dump_to(std::string &out) const override; #endif @@ -1843,7 +1843,7 @@ class BluetoothGATTDescriptor : public ProtoMessage { std::array uuid{}; uint32_t handle{0}; void encode(ProtoWriteBuffer buffer) const override; - void calculate_size(uint32_t &total_size) const override; + void calculate_size(ProtoSize &size) const override; #ifdef HAS_PROTO_MESSAGE_DUMP void dump_to(std::string &out) const override; #endif @@ -1857,7 +1857,7 @@ class BluetoothGATTCharacteristic : public ProtoMessage { uint32_t properties{0}; std::vector descriptors{}; void encode(ProtoWriteBuffer buffer) const override; - void calculate_size(uint32_t &total_size) const override; + void calculate_size(ProtoSize &size) const override; #ifdef HAS_PROTO_MESSAGE_DUMP void dump_to(std::string &out) const override; #endif @@ -1870,7 +1870,7 @@ class BluetoothGATTService : public ProtoMessage { uint32_t handle{0}; std::vector characteristics{}; void encode(ProtoWriteBuffer buffer) const override; - void calculate_size(uint32_t &total_size) const override; + void calculate_size(ProtoSize &size) const override; #ifdef HAS_PROTO_MESSAGE_DUMP void dump_to(std::string &out) const override; #endif @@ -1887,7 +1887,7 @@ class BluetoothGATTGetServicesResponse : public ProtoMessage { uint64_t address{0}; std::array services{}; void encode(ProtoWriteBuffer buffer) const override; - void calculate_size(uint32_t &total_size) const override; + void calculate_size(ProtoSize &size) const override; #ifdef HAS_PROTO_MESSAGE_DUMP void dump_to(std::string &out) const override; #endif @@ -1903,7 +1903,7 @@ class BluetoothGATTGetServicesDoneResponse : public ProtoMessage { #endif uint64_t address{0}; void encode(ProtoWriteBuffer buffer) const override; - void calculate_size(uint32_t &total_size) const override; + void calculate_size(ProtoSize &size) const override; #ifdef HAS_PROTO_MESSAGE_DUMP void dump_to(std::string &out) const override; #endif @@ -1942,7 +1942,7 @@ class BluetoothGATTReadResponse : public ProtoMessage { this->data_len_ = len; } void encode(ProtoWriteBuffer buffer) const override; - void calculate_size(uint32_t &total_size) const override; + void calculate_size(ProtoSize &size) const override; #ifdef HAS_PROTO_MESSAGE_DUMP void dump_to(std::string &out) const override; #endif @@ -2035,7 +2035,7 @@ class BluetoothGATTNotifyDataResponse : public ProtoMessage { this->data_len_ = len; } void encode(ProtoWriteBuffer buffer) const override; - void calculate_size(uint32_t &total_size) const override; + void calculate_size(ProtoSize &size) const override; #ifdef HAS_PROTO_MESSAGE_DUMP void dump_to(std::string &out) const override; #endif @@ -2066,7 +2066,7 @@ class BluetoothConnectionsFreeResponse : public ProtoMessage { uint32_t limit{0}; std::vector allocated{}; void encode(ProtoWriteBuffer buffer) const override; - void calculate_size(uint32_t &total_size) const override; + void calculate_size(ProtoSize &size) const override; #ifdef HAS_PROTO_MESSAGE_DUMP void dump_to(std::string &out) const override; #endif @@ -2084,7 +2084,7 @@ class BluetoothGATTErrorResponse : public ProtoMessage { uint32_t handle{0}; int32_t error{0}; void encode(ProtoWriteBuffer buffer) const override; - void calculate_size(uint32_t &total_size) const override; + void calculate_size(ProtoSize &size) const override; #ifdef HAS_PROTO_MESSAGE_DUMP void dump_to(std::string &out) const override; #endif @@ -2101,7 +2101,7 @@ class BluetoothGATTWriteResponse : public ProtoMessage { uint64_t address{0}; uint32_t handle{0}; void encode(ProtoWriteBuffer buffer) const override; - void calculate_size(uint32_t &total_size) const override; + void calculate_size(ProtoSize &size) const override; #ifdef HAS_PROTO_MESSAGE_DUMP void dump_to(std::string &out) const override; #endif @@ -2118,7 +2118,7 @@ class BluetoothGATTNotifyResponse : public ProtoMessage { uint64_t address{0}; uint32_t handle{0}; void encode(ProtoWriteBuffer buffer) const override; - void calculate_size(uint32_t &total_size) const override; + void calculate_size(ProtoSize &size) const override; #ifdef HAS_PROTO_MESSAGE_DUMP void dump_to(std::string &out) const override; #endif @@ -2136,7 +2136,7 @@ class BluetoothDevicePairingResponse : public ProtoMessage { bool paired{false}; int32_t error{0}; void encode(ProtoWriteBuffer buffer) const override; - void calculate_size(uint32_t &total_size) const override; + void calculate_size(ProtoSize &size) const override; #ifdef HAS_PROTO_MESSAGE_DUMP void dump_to(std::string &out) const override; #endif @@ -2154,7 +2154,7 @@ class BluetoothDeviceUnpairingResponse : public ProtoMessage { bool success{false}; int32_t error{0}; void encode(ProtoWriteBuffer buffer) const override; - void calculate_size(uint32_t &total_size) const override; + void calculate_size(ProtoSize &size) const override; #ifdef HAS_PROTO_MESSAGE_DUMP void dump_to(std::string &out) const override; #endif @@ -2185,7 +2185,7 @@ class BluetoothDeviceClearCacheResponse : public ProtoMessage { bool success{false}; int32_t error{0}; void encode(ProtoWriteBuffer buffer) const override; - void calculate_size(uint32_t &total_size) const override; + void calculate_size(ProtoSize &size) const override; #ifdef HAS_PROTO_MESSAGE_DUMP void dump_to(std::string &out) const override; #endif @@ -2202,7 +2202,7 @@ class BluetoothScannerStateResponse : public ProtoMessage { enums::BluetoothScannerState state{}; enums::BluetoothScannerMode mode{}; void encode(ProtoWriteBuffer buffer) const override; - void calculate_size(uint32_t &total_size) const override; + void calculate_size(ProtoSize &size) const override; #ifdef HAS_PROTO_MESSAGE_DUMP void dump_to(std::string &out) const override; #endif @@ -2248,7 +2248,7 @@ class VoiceAssistantAudioSettings : public ProtoMessage { uint32_t auto_gain{0}; float volume_multiplier{0.0f}; void encode(ProtoWriteBuffer buffer) const override; - void calculate_size(uint32_t &total_size) const override; + void calculate_size(ProtoSize &size) const override; #ifdef HAS_PROTO_MESSAGE_DUMP void dump_to(std::string &out) const override; #endif @@ -2270,7 +2270,7 @@ class VoiceAssistantRequest : public ProtoMessage { StringRef wake_word_phrase_ref_{}; void set_wake_word_phrase(const StringRef &ref) { this->wake_word_phrase_ref_ = ref; } void encode(ProtoWriteBuffer buffer) const override; - void calculate_size(uint32_t &total_size) const override; + void calculate_size(ProtoSize &size) const override; #ifdef HAS_PROTO_MESSAGE_DUMP void dump_to(std::string &out) const override; #endif @@ -2337,7 +2337,7 @@ class VoiceAssistantAudio : public ProtoDecodableMessage { } bool end{false}; void encode(ProtoWriteBuffer buffer) const override; - void calculate_size(uint32_t &total_size) const override; + void calculate_size(ProtoSize &size) const override; #ifdef HAS_PROTO_MESSAGE_DUMP void dump_to(std::string &out) const override; #endif @@ -2395,7 +2395,7 @@ class VoiceAssistantAnnounceFinished : public ProtoMessage { #endif bool success{false}; void encode(ProtoWriteBuffer buffer) const override; - void calculate_size(uint32_t &total_size) const override; + void calculate_size(ProtoSize &size) const override; #ifdef HAS_PROTO_MESSAGE_DUMP void dump_to(std::string &out) const override; #endif @@ -2410,7 +2410,7 @@ class VoiceAssistantWakeWord : public ProtoMessage { void set_wake_word(const StringRef &ref) { this->wake_word_ref_ = ref; } std::vector trained_languages{}; void encode(ProtoWriteBuffer buffer) const override; - void calculate_size(uint32_t &total_size) const override; + void calculate_size(ProtoSize &size) const override; #ifdef HAS_PROTO_MESSAGE_DUMP void dump_to(std::string &out) const override; #endif @@ -2441,7 +2441,7 @@ class VoiceAssistantConfigurationResponse : public ProtoMessage { std::vector active_wake_words{}; uint32_t max_active_wake_words{0}; void encode(ProtoWriteBuffer buffer) const override; - void calculate_size(uint32_t &total_size) const override; + void calculate_size(ProtoSize &size) const override; #ifdef HAS_PROTO_MESSAGE_DUMP void dump_to(std::string &out) const override; #endif @@ -2476,7 +2476,7 @@ class ListEntitiesAlarmControlPanelResponse : public InfoResponseProtoMessage { bool requires_code{false}; bool requires_code_to_arm{false}; void encode(ProtoWriteBuffer buffer) const override; - void calculate_size(uint32_t &total_size) const override; + void calculate_size(ProtoSize &size) const override; #ifdef HAS_PROTO_MESSAGE_DUMP void dump_to(std::string &out) const override; #endif @@ -2492,7 +2492,7 @@ class AlarmControlPanelStateResponse : public StateResponseProtoMessage { #endif enums::AlarmControlPanelState state{}; void encode(ProtoWriteBuffer buffer) const override; - void calculate_size(uint32_t &total_size) const override; + void calculate_size(ProtoSize &size) const override; #ifdef HAS_PROTO_MESSAGE_DUMP void dump_to(std::string &out) const override; #endif @@ -2532,7 +2532,7 @@ class ListEntitiesTextResponse : public InfoResponseProtoMessage { void set_pattern(const StringRef &ref) { this->pattern_ref_ = ref; } enums::TextMode mode{}; void encode(ProtoWriteBuffer buffer) const override; - void calculate_size(uint32_t &total_size) const override; + void calculate_size(ProtoSize &size) const override; #ifdef HAS_PROTO_MESSAGE_DUMP void dump_to(std::string &out) const override; #endif @@ -2550,7 +2550,7 @@ class TextStateResponse : public StateResponseProtoMessage { void set_state(const StringRef &ref) { this->state_ref_ = ref; } bool missing_state{false}; void encode(ProtoWriteBuffer buffer) const override; - void calculate_size(uint32_t &total_size) const override; + void calculate_size(ProtoSize &size) const override; #ifdef HAS_PROTO_MESSAGE_DUMP void dump_to(std::string &out) const override; #endif @@ -2584,7 +2584,7 @@ class ListEntitiesDateResponse : public InfoResponseProtoMessage { const char *message_name() const override { return "list_entities_date_response"; } #endif void encode(ProtoWriteBuffer buffer) const override; - void calculate_size(uint32_t &total_size) const override; + void calculate_size(ProtoSize &size) const override; #ifdef HAS_PROTO_MESSAGE_DUMP void dump_to(std::string &out) const override; #endif @@ -2603,7 +2603,7 @@ class DateStateResponse : public StateResponseProtoMessage { uint32_t month{0}; uint32_t day{0}; void encode(ProtoWriteBuffer buffer) const override; - void calculate_size(uint32_t &total_size) const override; + void calculate_size(ProtoSize &size) const override; #ifdef HAS_PROTO_MESSAGE_DUMP void dump_to(std::string &out) const override; #endif @@ -2638,7 +2638,7 @@ class ListEntitiesTimeResponse : public InfoResponseProtoMessage { const char *message_name() const override { return "list_entities_time_response"; } #endif void encode(ProtoWriteBuffer buffer) const override; - void calculate_size(uint32_t &total_size) const override; + void calculate_size(ProtoSize &size) const override; #ifdef HAS_PROTO_MESSAGE_DUMP void dump_to(std::string &out) const override; #endif @@ -2657,7 +2657,7 @@ class TimeStateResponse : public StateResponseProtoMessage { uint32_t minute{0}; uint32_t second{0}; void encode(ProtoWriteBuffer buffer) const override; - void calculate_size(uint32_t &total_size) const override; + void calculate_size(ProtoSize &size) const override; #ifdef HAS_PROTO_MESSAGE_DUMP void dump_to(std::string &out) const override; #endif @@ -2695,7 +2695,7 @@ class ListEntitiesEventResponse : public InfoResponseProtoMessage { void set_device_class(const StringRef &ref) { this->device_class_ref_ = ref; } std::vector event_types{}; void encode(ProtoWriteBuffer buffer) const override; - void calculate_size(uint32_t &total_size) const override; + void calculate_size(ProtoSize &size) const override; #ifdef HAS_PROTO_MESSAGE_DUMP void dump_to(std::string &out) const override; #endif @@ -2712,7 +2712,7 @@ class EventResponse : public StateResponseProtoMessage { StringRef event_type_ref_{}; void set_event_type(const StringRef &ref) { this->event_type_ref_ = ref; } void encode(ProtoWriteBuffer buffer) const override; - void calculate_size(uint32_t &total_size) const override; + void calculate_size(ProtoSize &size) const override; #ifdef HAS_PROTO_MESSAGE_DUMP void dump_to(std::string &out) const override; #endif @@ -2734,7 +2734,7 @@ class ListEntitiesValveResponse : public InfoResponseProtoMessage { bool supports_position{false}; bool supports_stop{false}; void encode(ProtoWriteBuffer buffer) const override; - void calculate_size(uint32_t &total_size) const override; + void calculate_size(ProtoSize &size) const override; #ifdef HAS_PROTO_MESSAGE_DUMP void dump_to(std::string &out) const override; #endif @@ -2751,7 +2751,7 @@ class ValveStateResponse : public StateResponseProtoMessage { float position{0.0f}; enums::ValveOperation current_operation{}; void encode(ProtoWriteBuffer buffer) const override; - void calculate_size(uint32_t &total_size) const override; + void calculate_size(ProtoSize &size) const override; #ifdef HAS_PROTO_MESSAGE_DUMP void dump_to(std::string &out) const override; #endif @@ -2786,7 +2786,7 @@ class ListEntitiesDateTimeResponse : public InfoResponseProtoMessage { const char *message_name() const override { return "list_entities_date_time_response"; } #endif void encode(ProtoWriteBuffer buffer) const override; - void calculate_size(uint32_t &total_size) const override; + void calculate_size(ProtoSize &size) const override; #ifdef HAS_PROTO_MESSAGE_DUMP void dump_to(std::string &out) const override; #endif @@ -2803,7 +2803,7 @@ class DateTimeStateResponse : public StateResponseProtoMessage { bool missing_state{false}; uint32_t epoch_seconds{0}; void encode(ProtoWriteBuffer buffer) const override; - void calculate_size(uint32_t &total_size) const override; + void calculate_size(ProtoSize &size) const override; #ifdef HAS_PROTO_MESSAGE_DUMP void dump_to(std::string &out) const override; #endif @@ -2838,7 +2838,7 @@ class ListEntitiesUpdateResponse : public InfoResponseProtoMessage { StringRef device_class_ref_{}; void set_device_class(const StringRef &ref) { this->device_class_ref_ = ref; } void encode(ProtoWriteBuffer buffer) const override; - void calculate_size(uint32_t &total_size) const override; + void calculate_size(ProtoSize &size) const override; #ifdef HAS_PROTO_MESSAGE_DUMP void dump_to(std::string &out) const override; #endif @@ -2867,7 +2867,7 @@ class UpdateStateResponse : public StateResponseProtoMessage { StringRef release_url_ref_{}; void set_release_url(const StringRef &ref) { this->release_url_ref_ = ref; } void encode(ProtoWriteBuffer buffer) const override; - void calculate_size(uint32_t &total_size) const override; + void calculate_size(ProtoSize &size) const override; #ifdef HAS_PROTO_MESSAGE_DUMP void dump_to(std::string &out) const override; #endif diff --git a/esphome/components/api/proto.h b/esphome/components/api/proto.h index 771eaa98d1..74a918751c 100644 --- a/esphome/components/api/proto.h +++ b/esphome/components/api/proto.h @@ -340,7 +340,7 @@ class ProtoMessage { // Default implementation for messages with no fields virtual void encode(ProtoWriteBuffer buffer) const {} // Default implementation for messages with no fields - virtual void calculate_size(uint32_t &total_size) const {} + virtual void calculate_size(ProtoSize &size) const {} #ifdef HAS_PROTO_MESSAGE_DUMP std::string dump() const; virtual void dump_to(std::string &out) const = 0; @@ -361,24 +361,32 @@ class ProtoDecodableMessage : public ProtoMessage { }; class ProtoSize { + private: + uint32_t total_size_ = 0; + public: /** * @brief 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. + * This class provides methods to calculate the exact byte counts needed + * for encoding various Protocol Buffer field types. The class now uses an + * object-based approach to reduce parameter passing overhead while keeping + * varint calculation methods static for external use. * * Implements Protocol Buffer encoding size calculation according to: * https://protobuf.dev/programming-guides/encoding/ * * Key features: + * - Object-based approach reduces flash usage by eliminating parameter passing * - Early-return optimization for zero/default values - * - Direct total_size updates to avoid unnecessary additions + * - Static varint methods for external callers * - Specialized handling for different field types according to protobuf spec - * - Templated helpers for repeated fields and messages */ + ProtoSize() = default; + + uint32_t get_size() const { return total_size_; } + /** * @brief Calculates the size in bytes needed to encode a uint32_t value as a varint * @@ -479,9 +487,7 @@ class ProtoSize { * @brief Common parameters for all add_*_field methods * * All add_*_field methods follow these common patterns: - * - * @param total_size Reference to the total message size to update - * @param field_id_size Pre-calculated size of the field ID in bytes + * * @param field_id_size Pre-calculated size of the field ID in bytes * @param value The value to calculate size for (type varies) * @param force Whether to calculate size even if the value is default/zero/empty * @@ -494,85 +500,85 @@ class ProtoSize { /** * @brief Calculates and adds the size of an int32 field to the total message size */ - static inline void add_int32_field(uint32_t &total_size, uint32_t field_id_size, int32_t value) { + inline void add_int32_field(uint32_t field_id_size, int32_t value) { // Skip calculation if value is zero if (value == 0) { - return; // No need to update total_size + return; // No need to update total_size_ } // Calculate and directly add to total_size if (value < 0) { // Negative values are encoded as 10-byte varints in protobuf - total_size += field_id_size + 10; + total_size_ += field_id_size + 10; } else { // For non-negative values, use the standard varint size - total_size += field_id_size + varint(static_cast(value)); + total_size_ += field_id_size + varint(static_cast(value)); } } /** * @brief Calculates and adds the size of an int32 field to the total message size (repeated field version) */ - static inline void add_int32_field_repeated(uint32_t &total_size, uint32_t field_id_size, int32_t value) { + inline void add_int32_field_repeated(uint32_t field_id_size, int32_t value) { // Always calculate size for repeated fields if (value < 0) { // Negative values are encoded as 10-byte varints in protobuf - total_size += field_id_size + 10; + total_size_ += field_id_size + 10; } else { // For non-negative values, use the standard varint size - total_size += field_id_size + varint(static_cast(value)); + total_size_ += field_id_size + varint(static_cast(value)); } } /** * @brief Calculates and adds the size of a uint32 field to the total message size */ - static inline void add_uint32_field(uint32_t &total_size, uint32_t field_id_size, uint32_t value) { + inline void add_uint32_field(uint32_t field_id_size, uint32_t value) { // Skip calculation if value is zero if (value == 0) { - return; // No need to update total_size + return; // No need to update total_size_ } // Calculate and directly add to total_size - total_size += field_id_size + varint(value); + total_size_ += field_id_size + varint(value); } /** * @brief Calculates and adds the size of a uint32 field to the total message size (repeated field version) */ - static inline void add_uint32_field_repeated(uint32_t &total_size, uint32_t field_id_size, uint32_t value) { + inline void add_uint32_field_repeated(uint32_t field_id_size, uint32_t value) { // Always calculate size for repeated fields - total_size += field_id_size + varint(value); + total_size_ += field_id_size + varint(value); } /** * @brief Calculates and adds the size of a boolean field to the total message size */ - static inline void add_bool_field(uint32_t &total_size, uint32_t field_id_size, bool value) { + inline void add_bool_field(uint32_t field_id_size, bool value) { // Skip calculation if value is false if (!value) { - return; // No need to update total_size + return; // No need to update total_size_ } // Boolean fields always use 1 byte when true - total_size += field_id_size + 1; + total_size_ += field_id_size + 1; } /** * @brief Calculates and adds the size of a boolean field to the total message size (repeated field version) */ - static inline void add_bool_field_repeated(uint32_t &total_size, uint32_t field_id_size, bool value) { + inline void add_bool_field_repeated(uint32_t field_id_size, bool value) { // Always calculate size for repeated fields // Boolean fields always use 1 byte - total_size += field_id_size + 1; + total_size_ += field_id_size + 1; } /** * @brief Calculates and adds the size of a float field to the total message size */ - static inline void add_float_field(uint32_t &total_size, uint32_t field_id_size, float value) { + inline void add_float_field(uint32_t field_id_size, float value) { if (value != 0.0f) { - total_size += field_id_size + 4; + total_size_ += field_id_size + 4; } } @@ -582,9 +588,9 @@ class ProtoSize { /** * @brief Calculates and adds the size of a fixed32 field to the total message size */ - static inline void add_fixed32_field(uint32_t &total_size, uint32_t field_id_size, uint32_t value) { + inline void add_fixed32_field(uint32_t field_id_size, uint32_t value) { if (value != 0) { - total_size += field_id_size + 4; + total_size_ += field_id_size + 4; } } @@ -594,9 +600,9 @@ class ProtoSize { /** * @brief Calculates and adds the size of a sfixed32 field to the total message size */ - static inline void add_sfixed32_field(uint32_t &total_size, uint32_t field_id_size, int32_t value) { + inline void add_sfixed32_field(uint32_t field_id_size, int32_t value) { if (value != 0) { - total_size += field_id_size + 4; + total_size_ += field_id_size + 4; } } @@ -608,14 +614,14 @@ class ProtoSize { * * Enum fields are encoded as uint32 varints. */ - static inline void add_enum_field(uint32_t &total_size, uint32_t field_id_size, uint32_t value) { + inline void add_enum_field(uint32_t field_id_size, uint32_t value) { // Skip calculation if value is zero if (value == 0) { - return; // No need to update total_size + return; // No need to update total_size_ } // Enums are encoded as uint32 - total_size += field_id_size + varint(value); + total_size_ += field_id_size + varint(value); } /** @@ -623,10 +629,10 @@ class ProtoSize { * * Enum fields are encoded as uint32 varints. */ - static inline void add_enum_field_repeated(uint32_t &total_size, uint32_t field_id_size, uint32_t value) { + inline void add_enum_field_repeated(uint32_t field_id_size, uint32_t value) { // Always calculate size for repeated fields // Enums are encoded as uint32 - total_size += field_id_size + varint(value); + total_size_ += field_id_size + varint(value); } /** @@ -634,15 +640,15 @@ class ProtoSize { * * Sint32 fields use ZigZag encoding, which is more efficient for negative values. */ - static inline void add_sint32_field(uint32_t &total_size, uint32_t field_id_size, int32_t value) { + inline void add_sint32_field(uint32_t field_id_size, int32_t value) { // Skip calculation if value is zero if (value == 0) { - return; // No need to update total_size + return; // No need to update total_size_ } // ZigZag encoding for sint32: (n << 1) ^ (n >> 31) uint32_t zigzag = (static_cast(value) << 1) ^ (static_cast(value >> 31)); - total_size += field_id_size + varint(zigzag); + total_size_ += field_id_size + varint(zigzag); } /** @@ -650,53 +656,53 @@ class ProtoSize { * * Sint32 fields use ZigZag encoding, which is more efficient for negative values. */ - static inline void add_sint32_field_repeated(uint32_t &total_size, uint32_t field_id_size, int32_t value) { + inline void add_sint32_field_repeated(uint32_t field_id_size, int32_t value) { // Always calculate size for repeated fields // ZigZag encoding for sint32: (n << 1) ^ (n >> 31) uint32_t zigzag = (static_cast(value) << 1) ^ (static_cast(value >> 31)); - total_size += field_id_size + varint(zigzag); + total_size_ += field_id_size + varint(zigzag); } /** * @brief Calculates and adds the size of an int64 field to the total message size */ - static inline void add_int64_field(uint32_t &total_size, uint32_t field_id_size, int64_t value) { + inline void add_int64_field(uint32_t field_id_size, int64_t value) { // Skip calculation if value is zero if (value == 0) { - return; // No need to update total_size + return; // No need to update total_size_ } // Calculate and directly add to total_size - total_size += field_id_size + varint(value); + total_size_ += field_id_size + varint(value); } /** * @brief Calculates and adds the size of an int64 field to the total message size (repeated field version) */ - static inline void add_int64_field_repeated(uint32_t &total_size, uint32_t field_id_size, int64_t value) { + inline void add_int64_field_repeated(uint32_t field_id_size, int64_t value) { // Always calculate size for repeated fields - total_size += field_id_size + varint(value); + total_size_ += field_id_size + varint(value); } /** * @brief Calculates and adds the size of a uint64 field to the total message size */ - static inline void add_uint64_field(uint32_t &total_size, uint32_t field_id_size, uint64_t value) { + inline void add_uint64_field(uint32_t field_id_size, uint64_t value) { // Skip calculation if value is zero if (value == 0) { - return; // No need to update total_size + return; // No need to update total_size_ } // Calculate and directly add to total_size - total_size += field_id_size + varint(value); + total_size_ += field_id_size + varint(value); } /** * @brief Calculates and adds the size of a uint64 field to the total message size (repeated field version) */ - static inline void add_uint64_field_repeated(uint32_t &total_size, uint32_t field_id_size, uint64_t value) { + inline void add_uint64_field_repeated(uint32_t field_id_size, uint64_t value) { // Always calculate size for repeated fields - total_size += field_id_size + varint(value); + total_size_ += field_id_size + varint(value); } // NOTE: sint64 support functions (add_sint64_field, add_sint64_field_repeated) removed @@ -705,38 +711,57 @@ class ProtoSize { /** * @brief Calculates and adds the size of a string field using length */ - static inline void add_string_field(uint32_t &total_size, uint32_t field_id_size, size_t len) { + inline void add_string_field(uint32_t field_id_size, size_t len) { // Skip calculation if string is empty if (len == 0) { - return; // No need to update total_size + return; // No need to update total_size_ } // Field ID + length varint + string bytes - total_size += field_id_size + varint(static_cast(len)) + static_cast(len); + total_size_ += field_id_size + varint(static_cast(len)) + static_cast(len); } /** * @brief Calculates and adds the size of a string/bytes field to the total message size (repeated field version) */ - static inline void add_string_field_repeated(uint32_t &total_size, uint32_t field_id_size, const std::string &str) { + inline void add_string_field_repeated(uint32_t field_id_size, const std::string &str) { // Always calculate size for repeated fields const uint32_t str_size = static_cast(str.size()); - total_size += field_id_size + varint(str_size) + str_size; + total_size_ += field_id_size + varint(str_size) + str_size; } /** * @brief Calculates and adds the size of a bytes field to the total message size */ - static inline void add_bytes_field(uint32_t &total_size, uint32_t field_id_size, size_t len) { + inline void add_bytes_field(uint32_t field_id_size, size_t len) { // Skip calculation if bytes is empty if (len == 0) { - return; // No need to update total_size + return; // No need to update total_size_ } // Field ID + length varint + data bytes - total_size += field_id_size + varint(static_cast(len)) + static_cast(len); + total_size_ += field_id_size + varint(static_cast(len)) + static_cast(len); } + /** + * @brief Calculates and adds the size of a bytes field to the total message size (repeated field version) + */ + inline void add_bytes_field_repeated(uint32_t field_id_size, size_t len) { + // Always calculate size for repeated fields + // Field ID + length varint + data bytes + total_size_ += field_id_size + varint(static_cast(len)) + static_cast(len); + } + + /** + * @brief Adds a pre-calculated size directly to the total + * + * This is used when we can calculate the total size by multiplying the number + * of elements by the bytes per element (for repeated fixed-size types like float, fixed32, etc.) + * + * @param size The pre-calculated total size to add + */ + inline void add_precalculated_size(uint32_t size) { total_size_ += size; } + /** * @brief Calculates and adds the size of a nested message field to the total message size * @@ -745,15 +770,15 @@ class ProtoSize { * * @param nested_size The pre-calculated size of the nested message */ - static inline void add_message_field(uint32_t &total_size, uint32_t field_id_size, uint32_t nested_size) { + inline void add_message_field(uint32_t field_id_size, uint32_t nested_size) { // Skip calculation if nested message is empty if (nested_size == 0) { - return; // No need to update total_size + return; // No need to update total_size_ } // Calculate and directly add to total_size // Field ID + length varint + nested message content - total_size += field_id_size + varint(nested_size) + nested_size; + total_size_ += field_id_size + varint(nested_size) + nested_size; } /** @@ -761,10 +786,10 @@ class ProtoSize { * * @param nested_size The pre-calculated size of the nested message */ - static inline void add_message_field_repeated(uint32_t &total_size, uint32_t field_id_size, uint32_t nested_size) { + inline void add_message_field_repeated(uint32_t field_id_size, uint32_t nested_size) { // Always calculate size for repeated fields // Field ID + length varint + nested message content - total_size += field_id_size + varint(nested_size) + nested_size; + total_size_ += field_id_size + varint(nested_size) + nested_size; } /** @@ -776,12 +801,14 @@ class ProtoSize { * * @param message The nested message object */ - static inline void add_message_object(uint32_t &total_size, uint32_t field_id_size, const ProtoMessage &message) { - uint32_t nested_size = 0; - message.calculate_size(nested_size); + inline void add_message_object(uint32_t field_id_size, const ProtoMessage &message) { + // Calculate nested message size by creating a temporary ProtoSize + ProtoSize nested_calc; + message.calculate_size(nested_calc); + uint32_t nested_size = nested_calc.get_size(); // Use the base implementation with the calculated nested_size - add_message_field(total_size, field_id_size, nested_size); + add_message_field(field_id_size, nested_size); } /** @@ -789,13 +816,14 @@ class ProtoSize { * * @param message The nested message object */ - static inline void add_message_object_repeated(uint32_t &total_size, uint32_t field_id_size, - const ProtoMessage &message) { - uint32_t nested_size = 0; - message.calculate_size(nested_size); + inline void add_message_object_repeated(uint32_t field_id_size, const ProtoMessage &message) { + // Calculate nested message size by creating a temporary ProtoSize + ProtoSize nested_calc; + message.calculate_size(nested_calc); + uint32_t nested_size = nested_calc.get_size(); // Use the base implementation with the calculated nested_size - add_message_field_repeated(total_size, field_id_size, nested_size); + add_message_field_repeated(field_id_size, nested_size); } /** @@ -808,8 +836,7 @@ class ProtoSize { * @param messages Vector of message objects */ template - static inline void add_repeated_message(uint32_t &total_size, uint32_t field_id_size, - const std::vector &messages) { + inline void add_repeated_message(uint32_t field_id_size, const std::vector &messages) { // Skip if the vector is empty if (messages.empty()) { return; @@ -817,7 +844,7 @@ class ProtoSize { // Use the repeated field version for all messages for (const auto &message : messages) { - add_message_object_repeated(total_size, field_id_size, message); + add_message_object_repeated(field_id_size, message); } } }; @@ -827,8 +854,9 @@ inline void ProtoWriteBuffer::encode_message(uint32_t field_id, const ProtoMessa this->encode_field_raw(field_id, 2); // type 2: Length-delimited message // Calculate the message size first - uint32_t msg_length_bytes = 0; - value.calculate_size(msg_length_bytes); + ProtoSize msg_size; + value.calculate_size(msg_size); + uint32_t msg_length_bytes = msg_size.get_size(); // Calculate how many bytes the length varint needs uint32_t varint_length_bytes = ProtoSize::varint(msg_length_bytes); @@ -877,8 +905,9 @@ class ProtoService { // Optimized method that pre-allocates buffer based on message size bool send_message_(const ProtoMessage &msg, uint8_t message_type) { - uint32_t msg_size = 0; - msg.calculate_size(msg_size); + ProtoSize size; + msg.calculate_size(size); + uint32_t msg_size = size.get_size(); // Create a pre-sized buffer auto buffer = this->create_buffer(msg_size); diff --git a/script/api_protobuf/api_protobuf.py b/script/api_protobuf/api_protobuf.py index 92c85d2366..2783d3bad7 100755 --- a/script/api_protobuf/api_protobuf.py +++ b/script/api_protobuf/api_protobuf.py @@ -281,7 +281,7 @@ class TypeInfo(ABC): field_id_size = self.calculate_field_id_size() method = f"{base_method}_repeated" if force else base_method value = value_expr if value_expr else name - return f"ProtoSize::{method}(total_size, {field_id_size}, {value});" + return f"size.{method}({field_id_size}, {value});" @abstractmethod def get_size_calculation(self, name: str, force: bool = False) -> str: @@ -389,7 +389,7 @@ class DoubleType(TypeInfo): def get_size_calculation(self, name: str, force: bool = False) -> str: field_id_size = self.calculate_field_id_size() - return f"ProtoSize::add_double_field(total_size, {field_id_size}, {name});" + return f"size.add_double_field({field_id_size}, {name});" def get_fixed_size_bytes(self) -> int: return 8 @@ -413,7 +413,7 @@ class FloatType(TypeInfo): def get_size_calculation(self, name: str, force: bool = False) -> str: field_id_size = self.calculate_field_id_size() - return f"ProtoSize::add_float_field(total_size, {field_id_size}, {name});" + return f"size.add_float_field({field_id_size}, {name});" def get_fixed_size_bytes(self) -> int: return 4 @@ -497,7 +497,7 @@ class Fixed64Type(TypeInfo): def get_size_calculation(self, name: str, force: bool = False) -> str: field_id_size = self.calculate_field_id_size() - return f"ProtoSize::add_fixed64_field(total_size, {field_id_size}, {name});" + return f"size.add_fixed64_field({field_id_size}, {name});" def get_fixed_size_bytes(self) -> int: return 8 @@ -521,7 +521,7 @@ class Fixed32Type(TypeInfo): def get_size_calculation(self, name: str, force: bool = False) -> str: field_id_size = self.calculate_field_id_size() - return f"ProtoSize::add_fixed32_field(total_size, {field_id_size}, {name});" + return f"size.add_fixed32_field({field_id_size}, {name});" def get_fixed_size_bytes(self) -> int: return 4 @@ -631,11 +631,11 @@ class StringType(TypeInfo): if name == "it": # For repeated fields, we need to use add_string_field_repeated which includes field ID field_id_size = self.calculate_field_id_size() - return f"ProtoSize::add_string_field_repeated(total_size, {field_id_size}, it);" + return f"size.add_string_field_repeated({field_id_size}, it);" # For messages that need encoding, use the StringRef size field_id_size = self.calculate_field_id_size() - return f"ProtoSize::add_string_field(total_size, {field_id_size}, this->{self.field_name}_ref_.size());" + return f"size.add_string_field({field_id_size}, this->{self.field_name}_ref_.size());" def get_estimated_size(self) -> int: return self.calculate_field_id_size() + 8 # field ID + 8 bytes typical string @@ -770,7 +770,7 @@ class BytesType(TypeInfo): return o def get_size_calculation(self, name: str, force: bool = False) -> str: - return f"ProtoSize::add_bytes_field(total_size, {self.calculate_field_id_size()}, this->{self.field_name}_len_);" + return f"size.add_bytes_field({self.calculate_field_id_size()}, this->{self.field_name}_len_);" def get_estimated_size(self) -> int: return self.calculate_field_id_size() + 8 # field ID + 8 bytes typical bytes @@ -845,15 +845,11 @@ class FixedArrayBytesType(TypeInfo): field_id_size = self.calculate_field_id_size() if force: - # For repeated fields, always calculate size - return f"total_size += {field_id_size} + ProtoSize::varint(static_cast({length_field})) + {length_field};" + # For repeated fields, always calculate size (no zero check) + return f"size.add_bytes_field_repeated({field_id_size}, {length_field});" else: - # For non-repeated fields, skip if length is 0 (matching encode_string behavior) - return ( - f"if ({length_field} != 0) {{\n" - f" total_size += {field_id_size} + ProtoSize::varint(static_cast({length_field})) + {length_field};\n" - f"}}" - ) + # For non-repeated fields, add_bytes_field already checks for zero + return f"size.add_bytes_field({field_id_size}, {length_field});" def get_estimated_size(self) -> int: # Estimate based on typical BLE advertisement size @@ -939,7 +935,7 @@ class SFixed32Type(TypeInfo): def get_size_calculation(self, name: str, force: bool = False) -> str: field_id_size = self.calculate_field_id_size() - return f"ProtoSize::add_sfixed32_field(total_size, {field_id_size}, {name});" + return f"size.add_sfixed32_field({field_id_size}, {name});" def get_fixed_size_bytes(self) -> int: return 4 @@ -963,7 +959,7 @@ class SFixed64Type(TypeInfo): def get_size_calculation(self, name: str, force: bool = False) -> str: field_id_size = self.calculate_field_id_size() - return f"ProtoSize::add_sfixed64_field(total_size, {field_id_size}, {name});" + return f"size.add_sfixed64_field({field_id_size}, {name});" def get_fixed_size_bytes(self) -> int: return 8 @@ -1240,7 +1236,7 @@ class RepeatedTypeInfo(TypeInfo): if isinstance(self._ti, MessageType): # For repeated messages, use the dedicated helper that handles iteration internally field_id_size = self._ti.calculate_field_id_size() - o = f"ProtoSize::add_repeated_message(total_size, {field_id_size}, {name});" + o = f"size.add_repeated_message({field_id_size}, {name});" return o # For other repeated types, use the underlying type's size calculation with force=True @@ -1253,7 +1249,9 @@ class RepeatedTypeInfo(TypeInfo): field_id_size = self._ti.calculate_field_id_size() # Pre-calculate the total bytes per element bytes_per_element = field_id_size + num_bytes - o += f" total_size += {name}.size() * {bytes_per_element};\n" + o += ( + f" size.add_precalculated_size({name}.size() * {bytes_per_element});\n" + ) else: # Other types need the actual value o += f" for (const auto {'' if self._ti_is_bool else '&'}it : {name}) {{\n" @@ -1685,7 +1683,7 @@ def build_message_type( if needs_encode and encode: o = f"void {desc.name}::encode(ProtoWriteBuffer buffer) const {{" if len(encode) == 1 and len(encode[0]) + len(o) + 3 < 120: - o += f" {encode[0]} " + o += f" {encode[0]} }}\n" else: o += "\n" o += indent("\n".join(encode)) + "\n" @@ -1697,17 +1695,17 @@ def build_message_type( # Add calculate_size method only if this message needs encoding and has fields if needs_encode and size_calc: - o = f"void {desc.name}::calculate_size(uint32_t &total_size) const {{" + o = f"void {desc.name}::calculate_size(ProtoSize &size) const {{" # For a single field, just inline it for simplicity if len(size_calc) == 1 and len(size_calc[0]) + len(o) + 3 < 120: - o += f" {size_calc[0]} " + o += f" {size_calc[0]} }}\n" else: # For multiple fields o += "\n" o += indent("\n".join(size_calc)) + "\n" o += "}\n" cpp += o - prot = "void calculate_size(uint32_t &total_size) const override;" + prot = "void calculate_size(ProtoSize &size) const override;" public_content.append(prot) # If no fields to calculate size for or message doesn't need encoding, the default implementation in ProtoMessage will be used