From e285fd681501e7bc4d782c6f56d29c3360e59d64 Mon Sep 17 00:00:00 2001 From: "J. Nick Koston" Date: Sun, 8 Mar 2026 17:13:03 -1000 Subject: [PATCH 01/15] [api] Inline ProtoVarInt::parse fast path and return consumed in struct MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Replace optional + consumed pointer with ProtoVarIntResult struct that returns value + consumed count directly. This eliminates memory stores through a pointer on the fast path (single-byte varints < 128), keeping everything in registers. The parse() method is now ESPHOME_ALWAYS_INLINE with the multi-byte slow path outlined to parse_slow_(). The common case for protobuf field tags, small enums, booleans, and typical message sizes/types is a simple high-bit check + register return with no function call. Measured on ESP32 (Xtensa): try_read_frame_ grows only +12 bytes (320 → 332) for two inlined parse sites, while eliminating two function calls per message on the hot path. --- .../api/api_frame_helper_plaintext.cpp | 19 ++-- esphome/components/api/api_pb2.cpp | 102 +++++++++--------- esphome/components/api/api_pb2.h | 102 +++++++++--------- esphome/components/api/proto.cpp | 70 +++++++----- esphome/components/api/proto.h | 81 +++++++------- script/api_protobuf/api_protobuf.py | 6 +- 6 files changed, 196 insertions(+), 184 deletions(-) diff --git a/esphome/components/api/api_frame_helper_plaintext.cpp b/esphome/components/api/api_frame_helper_plaintext.cpp index 3c54ed7c70..2fdcd87da5 100644 --- a/esphome/components/api/api_frame_helper_plaintext.cpp +++ b/esphome/components/api/api_frame_helper_plaintext.cpp @@ -128,37 +128,36 @@ APIError APIPlaintextFrameHelper::try_read_frame_() { // Skip indicator byte at position 0 uint8_t varint_pos = 1; - uint32_t consumed = 0; - auto msg_size_varint = ProtoVarInt::parse(&rx_header_buf_[varint_pos], rx_header_buf_pos_ - varint_pos, &consumed); + auto msg_size_varint = ProtoVarInt::parse(&rx_header_buf_[varint_pos], rx_header_buf_pos_ - varint_pos); if (!msg_size_varint.has_value()) { // not enough data there yet continue; } - if (msg_size_varint->as_uint32() > MAX_MESSAGE_SIZE) { + if (msg_size_varint.as_uint32() > MAX_MESSAGE_SIZE) { state_ = State::FAILED; - HELPER_LOG("Bad packet: message size %" PRIu32 " exceeds maximum %u", msg_size_varint->as_uint32(), + HELPER_LOG("Bad packet: message size %" PRIu32 " exceeds maximum %u", msg_size_varint.as_uint32(), MAX_MESSAGE_SIZE); return APIError::BAD_DATA_PACKET; } - rx_header_parsed_len_ = msg_size_varint->as_uint16(); + rx_header_parsed_len_ = msg_size_varint.as_uint16(); // Move to next varint position - varint_pos += consumed; + varint_pos += msg_size_varint.consumed; - auto msg_type_varint = ProtoVarInt::parse(&rx_header_buf_[varint_pos], rx_header_buf_pos_ - varint_pos, &consumed); + auto msg_type_varint = ProtoVarInt::parse(&rx_header_buf_[varint_pos], rx_header_buf_pos_ - varint_pos); if (!msg_type_varint.has_value()) { // not enough data there yet continue; } - if (msg_type_varint->as_uint32() > std::numeric_limits::max()) { + if (msg_type_varint.as_uint32() > std::numeric_limits::max()) { state_ = State::FAILED; - HELPER_LOG("Bad packet: message type %" PRIu32 " exceeds maximum %u", msg_type_varint->as_uint32(), + HELPER_LOG("Bad packet: message type %" PRIu32 " exceeds maximum %u", msg_type_varint.as_uint32(), std::numeric_limits::max()); return APIError::BAD_DATA_PACKET; } - rx_header_parsed_type_ = msg_type_varint->as_uint16(); + rx_header_parsed_type_ = msg_type_varint.as_uint16(); rx_header_parsed_ = true; } // header reading done diff --git a/esphome/components/api/api_pb2.cpp b/esphome/components/api/api_pb2.cpp index 6fce10ca0f..7d32a5123e 100644 --- a/esphome/components/api/api_pb2.cpp +++ b/esphome/components/api/api_pb2.cpp @@ -7,7 +7,7 @@ namespace esphome::api { -bool HelloRequest::decode_varint(uint32_t field_id, ProtoVarInt value) { +bool HelloRequest::decode_varint(uint32_t field_id, ProtoVarIntResult value) { switch (field_id) { case 2: this->api_version_major = value.as_uint32(); @@ -316,7 +316,7 @@ uint32_t CoverStateResponse::calculate_size() const { #endif return size; } -bool CoverCommandRequest::decode_varint(uint32_t field_id, ProtoVarInt value) { +bool CoverCommandRequest::decode_varint(uint32_t field_id, ProtoVarIntResult value) { switch (field_id) { case 4: this->has_position = value.as_bool(); @@ -423,7 +423,7 @@ uint32_t FanStateResponse::calculate_size() const { #endif return size; } -bool FanCommandRequest::decode_varint(uint32_t field_id, ProtoVarInt value) { +bool FanCommandRequest::decode_varint(uint32_t field_id, ProtoVarIntResult value) { switch (field_id) { case 2: this->has_state = value.as_bool(); @@ -571,7 +571,7 @@ uint32_t LightStateResponse::calculate_size() const { #endif return size; } -bool LightCommandRequest::decode_varint(uint32_t field_id, ProtoVarInt value) { +bool LightCommandRequest::decode_varint(uint32_t field_id, ProtoVarIntResult value) { switch (field_id) { case 2: this->has_state = value.as_bool(); @@ -787,7 +787,7 @@ uint32_t SwitchStateResponse::calculate_size() const { #endif return size; } -bool SwitchCommandRequest::decode_varint(uint32_t field_id, ProtoVarInt value) { +bool SwitchCommandRequest::decode_varint(uint32_t field_id, ProtoVarIntResult value) { switch (field_id) { case 2: this->state = value.as_bool(); @@ -863,7 +863,7 @@ uint32_t TextSensorStateResponse::calculate_size() const { return size; } #endif -bool SubscribeLogsRequest::decode_varint(uint32_t field_id, ProtoVarInt value) { +bool SubscribeLogsRequest::decode_varint(uint32_t field_id, ProtoVarIntResult value) { switch (field_id) { case 1: this->level = static_cast(value.as_uint32()); @@ -971,7 +971,7 @@ uint32_t HomeassistantActionRequest::calculate_size() const { } #endif #ifdef USE_API_HOMEASSISTANT_ACTION_RESPONSES -bool HomeassistantActionResponse::decode_varint(uint32_t field_id, ProtoVarInt value) { +bool HomeassistantActionResponse::decode_varint(uint32_t field_id, ProtoVarIntResult value) { switch (field_id) { case 1: this->call_id = value.as_uint32(); @@ -1036,7 +1036,7 @@ bool HomeAssistantStateResponse::decode_length(uint32_t field_id, ProtoLengthDel return true; } #endif -bool DSTRule::decode_varint(uint32_t field_id, ProtoVarInt value) { +bool DSTRule::decode_varint(uint32_t field_id, ProtoVarIntResult value) { switch (field_id) { case 1: this->time_seconds = value.as_sint32(); @@ -1061,7 +1061,7 @@ bool DSTRule::decode_varint(uint32_t field_id, ProtoVarInt value) { } return true; } -bool ParsedTimezone::decode_varint(uint32_t field_id, ProtoVarInt value) { +bool ParsedTimezone::decode_varint(uint32_t field_id, ProtoVarIntResult value) { switch (field_id) { case 1: this->std_offset_seconds = value.as_sint32(); @@ -1142,7 +1142,7 @@ uint32_t ListEntitiesServicesResponse::calculate_size() const { size += ProtoSize::calc_uint32(1, static_cast(this->supports_response)); return size; } -bool ExecuteServiceArgument::decode_varint(uint32_t field_id, ProtoVarInt value) { +bool ExecuteServiceArgument::decode_varint(uint32_t field_id, ProtoVarIntResult value) { switch (field_id) { case 1: this->bool_ = value.as_bool(); @@ -1202,7 +1202,7 @@ void ExecuteServiceArgument::decode(const uint8_t *buffer, size_t length) { this->string_array.init(count_string_array); ProtoDecodableMessage::decode(buffer, length); } -bool ExecuteServiceRequest::decode_varint(uint32_t field_id, ProtoVarInt value) { +bool ExecuteServiceRequest::decode_varint(uint32_t field_id, ProtoVarIntResult value) { switch (field_id) { #ifdef USE_API_USER_DEFINED_ACTION_RESPONSES case 3: @@ -1313,7 +1313,7 @@ uint32_t CameraImageResponse::calculate_size() const { #endif return size; } -bool CameraImageRequest::decode_varint(uint32_t field_id, ProtoVarInt value) { +bool CameraImageRequest::decode_varint(uint32_t field_id, ProtoVarIntResult value) { switch (field_id) { case 1: this->single = value.as_bool(); @@ -1468,7 +1468,7 @@ uint32_t ClimateStateResponse::calculate_size() const { #endif return size; } -bool ClimateCommandRequest::decode_varint(uint32_t field_id, ProtoVarInt value) { +bool ClimateCommandRequest::decode_varint(uint32_t field_id, ProtoVarIntResult value) { switch (field_id) { case 2: this->has_mode = value.as_bool(); @@ -1631,7 +1631,7 @@ uint32_t WaterHeaterStateResponse::calculate_size() const { size += ProtoSize::calc_float(1, this->target_temperature_high); return size; } -bool WaterHeaterCommandRequest::decode_varint(uint32_t field_id, ProtoVarInt value) { +bool WaterHeaterCommandRequest::decode_varint(uint32_t field_id, ProtoVarIntResult value) { switch (field_id) { case 2: this->has_fields = value.as_uint32(); @@ -1731,7 +1731,7 @@ uint32_t NumberStateResponse::calculate_size() const { #endif return size; } -bool NumberCommandRequest::decode_varint(uint32_t field_id, ProtoVarInt value) { +bool NumberCommandRequest::decode_varint(uint32_t field_id, ProtoVarIntResult value) { switch (field_id) { #ifdef USE_DEVICES case 3: @@ -1812,7 +1812,7 @@ uint32_t SelectStateResponse::calculate_size() const { #endif return size; } -bool SelectCommandRequest::decode_varint(uint32_t field_id, ProtoVarInt value) { +bool SelectCommandRequest::decode_varint(uint32_t field_id, ProtoVarIntResult value) { switch (field_id) { #ifdef USE_DEVICES case 3: @@ -1903,7 +1903,7 @@ uint32_t SirenStateResponse::calculate_size() const { #endif return size; } -bool SirenCommandRequest::decode_varint(uint32_t field_id, ProtoVarInt value) { +bool SirenCommandRequest::decode_varint(uint32_t field_id, ProtoVarIntResult value) { switch (field_id) { case 2: this->has_state = value.as_bool(); @@ -2011,7 +2011,7 @@ uint32_t LockStateResponse::calculate_size() const { #endif return size; } -bool LockCommandRequest::decode_varint(uint32_t field_id, ProtoVarInt value) { +bool LockCommandRequest::decode_varint(uint32_t field_id, ProtoVarIntResult value) { switch (field_id) { case 2: this->command = static_cast(value.as_uint32()); @@ -2082,7 +2082,7 @@ uint32_t ListEntitiesButtonResponse::calculate_size() const { #endif return size; } -bool ButtonCommandRequest::decode_varint(uint32_t field_id, ProtoVarInt value) { +bool ButtonCommandRequest::decode_varint(uint32_t field_id, ProtoVarIntResult value) { switch (field_id) { #ifdef USE_DEVICES case 2: @@ -2182,7 +2182,7 @@ uint32_t MediaPlayerStateResponse::calculate_size() const { #endif return size; } -bool MediaPlayerCommandRequest::decode_varint(uint32_t field_id, ProtoVarInt value) { +bool MediaPlayerCommandRequest::decode_varint(uint32_t field_id, ProtoVarIntResult value) { switch (field_id) { case 2: this->has_command = value.as_bool(); @@ -2238,7 +2238,7 @@ bool MediaPlayerCommandRequest::decode_32bit(uint32_t field_id, Proto32Bit value } #endif #ifdef USE_BLUETOOTH_PROXY -bool SubscribeBluetoothLEAdvertisementsRequest::decode_varint(uint32_t field_id, ProtoVarInt value) { +bool SubscribeBluetoothLEAdvertisementsRequest::decode_varint(uint32_t field_id, ProtoVarIntResult value) { switch (field_id) { case 1: this->flags = value.as_uint32(); @@ -2274,7 +2274,7 @@ uint32_t BluetoothLERawAdvertisementsResponse::calculate_size() const { } return size; } -bool BluetoothDeviceRequest::decode_varint(uint32_t field_id, ProtoVarInt value) { +bool BluetoothDeviceRequest::decode_varint(uint32_t field_id, ProtoVarIntResult value) { switch (field_id) { case 1: this->address = value.as_uint64(); @@ -2307,7 +2307,7 @@ uint32_t BluetoothDeviceConnectionResponse::calculate_size() const { size += ProtoSize::calc_int32(1, this->error); return size; } -bool BluetoothGATTGetServicesRequest::decode_varint(uint32_t field_id, ProtoVarInt value) { +bool BluetoothGATTGetServicesRequest::decode_varint(uint32_t field_id, ProtoVarIntResult value) { switch (field_id) { case 1: this->address = value.as_uint64(); @@ -2413,7 +2413,7 @@ uint32_t BluetoothGATTGetServicesDoneResponse::calculate_size() const { size += ProtoSize::calc_uint64(1, this->address); return size; } -bool BluetoothGATTReadRequest::decode_varint(uint32_t field_id, ProtoVarInt value) { +bool BluetoothGATTReadRequest::decode_varint(uint32_t field_id, ProtoVarIntResult value) { switch (field_id) { case 1: this->address = value.as_uint64(); @@ -2438,7 +2438,7 @@ uint32_t BluetoothGATTReadResponse::calculate_size() const { size += ProtoSize::calc_length(1, this->data_len_); return size; } -bool BluetoothGATTWriteRequest::decode_varint(uint32_t field_id, ProtoVarInt value) { +bool BluetoothGATTWriteRequest::decode_varint(uint32_t field_id, ProtoVarIntResult value) { switch (field_id) { case 1: this->address = value.as_uint64(); @@ -2466,7 +2466,7 @@ bool BluetoothGATTWriteRequest::decode_length(uint32_t field_id, ProtoLengthDeli } return true; } -bool BluetoothGATTReadDescriptorRequest::decode_varint(uint32_t field_id, ProtoVarInt value) { +bool BluetoothGATTReadDescriptorRequest::decode_varint(uint32_t field_id, ProtoVarIntResult value) { switch (field_id) { case 1: this->address = value.as_uint64(); @@ -2479,7 +2479,7 @@ bool BluetoothGATTReadDescriptorRequest::decode_varint(uint32_t field_id, ProtoV } return true; } -bool BluetoothGATTWriteDescriptorRequest::decode_varint(uint32_t field_id, ProtoVarInt value) { +bool BluetoothGATTWriteDescriptorRequest::decode_varint(uint32_t field_id, ProtoVarIntResult value) { switch (field_id) { case 1: this->address = value.as_uint64(); @@ -2504,7 +2504,7 @@ bool BluetoothGATTWriteDescriptorRequest::decode_length(uint32_t field_id, Proto } return true; } -bool BluetoothGATTNotifyRequest::decode_varint(uint32_t field_id, ProtoVarInt value) { +bool BluetoothGATTNotifyRequest::decode_varint(uint32_t field_id, ProtoVarIntResult value) { switch (field_id) { case 1: this->address = value.as_uint64(); @@ -2632,7 +2632,7 @@ uint32_t BluetoothScannerStateResponse::calculate_size() const { size += ProtoSize::calc_uint32(1, static_cast(this->configured_mode)); return size; } -bool BluetoothScannerSetModeRequest::decode_varint(uint32_t field_id, ProtoVarInt value) { +bool BluetoothScannerSetModeRequest::decode_varint(uint32_t field_id, ProtoVarIntResult value) { switch (field_id) { case 1: this->mode = static_cast(value.as_uint32()); @@ -2644,7 +2644,7 @@ bool BluetoothScannerSetModeRequest::decode_varint(uint32_t field_id, ProtoVarIn } #endif #ifdef USE_VOICE_ASSISTANT -bool SubscribeVoiceAssistantRequest::decode_varint(uint32_t field_id, ProtoVarInt value) { +bool SubscribeVoiceAssistantRequest::decode_varint(uint32_t field_id, ProtoVarIntResult value) { switch (field_id) { case 1: this->subscribe = value.as_bool(); @@ -2685,7 +2685,7 @@ uint32_t VoiceAssistantRequest::calculate_size() const { size += ProtoSize::calc_length(1, this->wake_word_phrase.size()); return size; } -bool VoiceAssistantResponse::decode_varint(uint32_t field_id, ProtoVarInt value) { +bool VoiceAssistantResponse::decode_varint(uint32_t field_id, ProtoVarIntResult value) { switch (field_id) { case 1: this->port = value.as_uint32(); @@ -2713,7 +2713,7 @@ bool VoiceAssistantEventData::decode_length(uint32_t field_id, ProtoLengthDelimi } return true; } -bool VoiceAssistantEventResponse::decode_varint(uint32_t field_id, ProtoVarInt value) { +bool VoiceAssistantEventResponse::decode_varint(uint32_t field_id, ProtoVarIntResult value) { switch (field_id) { case 1: this->event_type = static_cast(value.as_uint32()); @@ -2734,7 +2734,7 @@ bool VoiceAssistantEventResponse::decode_length(uint32_t field_id, ProtoLengthDe } return true; } -bool VoiceAssistantAudio::decode_varint(uint32_t field_id, ProtoVarInt value) { +bool VoiceAssistantAudio::decode_varint(uint32_t field_id, ProtoVarIntResult value) { switch (field_id) { case 2: this->end = value.as_bool(); @@ -2766,7 +2766,7 @@ uint32_t VoiceAssistantAudio::calculate_size() const { size += ProtoSize::calc_bool(1, this->end); return size; } -bool VoiceAssistantTimerEventResponse::decode_varint(uint32_t field_id, ProtoVarInt value) { +bool VoiceAssistantTimerEventResponse::decode_varint(uint32_t field_id, ProtoVarIntResult value) { switch (field_id) { case 1: this->event_type = static_cast(value.as_uint32()); @@ -2800,7 +2800,7 @@ bool VoiceAssistantTimerEventResponse::decode_length(uint32_t field_id, ProtoLen } return true; } -bool VoiceAssistantAnnounceRequest::decode_varint(uint32_t field_id, ProtoVarInt value) { +bool VoiceAssistantAnnounceRequest::decode_varint(uint32_t field_id, ProtoVarIntResult value) { switch (field_id) { case 4: this->start_conversation = value.as_bool(); @@ -2853,7 +2853,7 @@ uint32_t VoiceAssistantWakeWord::calculate_size() const { } return size; } -bool VoiceAssistantExternalWakeWord::decode_varint(uint32_t field_id, ProtoVarInt value) { +bool VoiceAssistantExternalWakeWord::decode_varint(uint32_t field_id, ProtoVarIntResult value) { switch (field_id) { case 5: this->model_size = value.as_uint32(); @@ -2990,7 +2990,7 @@ uint32_t AlarmControlPanelStateResponse::calculate_size() const { #endif return size; } -bool AlarmControlPanelCommandRequest::decode_varint(uint32_t field_id, ProtoVarInt value) { +bool AlarmControlPanelCommandRequest::decode_varint(uint32_t field_id, ProtoVarIntResult value) { switch (field_id) { case 2: this->command = static_cast(value.as_uint32()); @@ -3082,7 +3082,7 @@ uint32_t TextStateResponse::calculate_size() const { #endif return size; } -bool TextCommandRequest::decode_varint(uint32_t field_id, ProtoVarInt value) { +bool TextCommandRequest::decode_varint(uint32_t field_id, ProtoVarIntResult value) { switch (field_id) { #ifdef USE_DEVICES case 3: @@ -3167,7 +3167,7 @@ uint32_t DateStateResponse::calculate_size() const { #endif return size; } -bool DateCommandRequest::decode_varint(uint32_t field_id, ProtoVarInt value) { +bool DateCommandRequest::decode_varint(uint32_t field_id, ProtoVarIntResult value) { switch (field_id) { case 2: this->year = value.as_uint32(); @@ -3250,7 +3250,7 @@ uint32_t TimeStateResponse::calculate_size() const { #endif return size; } -bool TimeCommandRequest::decode_varint(uint32_t field_id, ProtoVarInt value) { +bool TimeCommandRequest::decode_varint(uint32_t field_id, ProtoVarIntResult value) { switch (field_id) { case 2: this->hour = value.as_uint32(); @@ -3393,7 +3393,7 @@ uint32_t ValveStateResponse::calculate_size() const { #endif return size; } -bool ValveCommandRequest::decode_varint(uint32_t field_id, ProtoVarInt value) { +bool ValveCommandRequest::decode_varint(uint32_t field_id, ProtoVarIntResult value) { switch (field_id) { case 2: this->has_position = value.as_bool(); @@ -3472,7 +3472,7 @@ uint32_t DateTimeStateResponse::calculate_size() const { #endif return size; } -bool DateTimeCommandRequest::decode_varint(uint32_t field_id, ProtoVarInt value) { +bool DateTimeCommandRequest::decode_varint(uint32_t field_id, ProtoVarIntResult value) { switch (field_id) { #ifdef USE_DEVICES case 3: @@ -3561,7 +3561,7 @@ uint32_t UpdateStateResponse::calculate_size() const { #endif return size; } -bool UpdateCommandRequest::decode_varint(uint32_t field_id, ProtoVarInt value) { +bool UpdateCommandRequest::decode_varint(uint32_t field_id, ProtoVarIntResult value) { switch (field_id) { case 2: this->command = static_cast(value.as_uint32()); @@ -3606,7 +3606,7 @@ uint32_t ZWaveProxyFrame::calculate_size() const { size += ProtoSize::calc_length(1, this->data_len); return size; } -bool ZWaveProxyRequest::decode_varint(uint32_t field_id, ProtoVarInt value) { +bool ZWaveProxyRequest::decode_varint(uint32_t field_id, ProtoVarIntResult value) { switch (field_id) { case 1: this->type = static_cast(value.as_uint32()); @@ -3672,7 +3672,7 @@ uint32_t ListEntitiesInfraredResponse::calculate_size() const { } #endif #ifdef USE_IR_RF -bool InfraredRFTransmitRawTimingsRequest::decode_varint(uint32_t field_id, ProtoVarInt value) { +bool InfraredRFTransmitRawTimingsRequest::decode_varint(uint32_t field_id, ProtoVarIntResult value) { switch (field_id) { #ifdef USE_DEVICES case 1: @@ -3737,7 +3737,7 @@ uint32_t InfraredRFReceiveEvent::calculate_size() const { } #endif #ifdef USE_SERIAL_PROXY -bool SerialProxyConfigureRequest::decode_varint(uint32_t field_id, ProtoVarInt value) { +bool SerialProxyConfigureRequest::decode_varint(uint32_t field_id, ProtoVarIntResult value) { switch (field_id) { case 1: this->instance = value.as_uint32(); @@ -3772,7 +3772,7 @@ uint32_t SerialProxyDataReceived::calculate_size() const { size += ProtoSize::calc_length(1, this->data_len_); return size; } -bool SerialProxyWriteRequest::decode_varint(uint32_t field_id, ProtoVarInt value) { +bool SerialProxyWriteRequest::decode_varint(uint32_t field_id, ProtoVarIntResult value) { switch (field_id) { case 1: this->instance = value.as_uint32(); @@ -3794,7 +3794,7 @@ bool SerialProxyWriteRequest::decode_length(uint32_t field_id, ProtoLengthDelimi } return true; } -bool SerialProxySetModemPinsRequest::decode_varint(uint32_t field_id, ProtoVarInt value) { +bool SerialProxySetModemPinsRequest::decode_varint(uint32_t field_id, ProtoVarIntResult value) { switch (field_id) { case 1: this->instance = value.as_uint32(); @@ -3807,7 +3807,7 @@ bool SerialProxySetModemPinsRequest::decode_varint(uint32_t field_id, ProtoVarIn } return true; } -bool SerialProxyGetModemPinsRequest::decode_varint(uint32_t field_id, ProtoVarInt value) { +bool SerialProxyGetModemPinsRequest::decode_varint(uint32_t field_id, ProtoVarIntResult value) { switch (field_id) { case 1: this->instance = value.as_uint32(); @@ -3827,7 +3827,7 @@ uint32_t SerialProxyGetModemPinsResponse::calculate_size() const { size += ProtoSize::calc_uint32(1, this->line_states); return size; } -bool SerialProxyRequest::decode_varint(uint32_t field_id, ProtoVarInt value) { +bool SerialProxyRequest::decode_varint(uint32_t field_id, ProtoVarIntResult value) { switch (field_id) { case 1: this->instance = value.as_uint32(); @@ -3856,7 +3856,7 @@ uint32_t SerialProxyRequestResponse::calculate_size() const { } #endif #ifdef USE_BLUETOOTH_PROXY -bool BluetoothSetConnectionParamsRequest::decode_varint(uint32_t field_id, ProtoVarInt value) { +bool BluetoothSetConnectionParamsRequest::decode_varint(uint32_t field_id, ProtoVarIntResult value) { switch (field_id) { case 1: this->address = value.as_uint64(); diff --git a/esphome/components/api/api_pb2.h b/esphome/components/api/api_pb2.h index 5c712508b9..c777140bda 100644 --- a/esphome/components/api/api_pb2.h +++ b/esphome/components/api/api_pb2.h @@ -399,7 +399,7 @@ class HelloRequest final : public ProtoDecodableMessage { protected: bool decode_length(uint32_t field_id, ProtoLengthDelimited value) override; - bool decode_varint(uint32_t field_id, ProtoVarInt value) override; + bool decode_varint(uint32_t field_id, ProtoVarIntResult value) override; }; class HelloResponse final : public ProtoMessage { public: @@ -688,7 +688,7 @@ class CoverCommandRequest final : public CommandProtoMessage { protected: bool decode_32bit(uint32_t field_id, Proto32Bit value) override; - bool decode_varint(uint32_t field_id, ProtoVarInt value) override; + bool decode_varint(uint32_t field_id, ProtoVarIntResult value) override; }; #endif #ifdef USE_FAN @@ -756,7 +756,7 @@ class FanCommandRequest final : public CommandProtoMessage { protected: bool decode_32bit(uint32_t field_id, Proto32Bit value) override; bool decode_length(uint32_t field_id, ProtoLengthDelimited value) override; - bool decode_varint(uint32_t field_id, ProtoVarInt value) override; + bool decode_varint(uint32_t field_id, ProtoVarIntResult value) override; }; #endif #ifdef USE_LIGHT @@ -846,7 +846,7 @@ class LightCommandRequest final : public CommandProtoMessage { protected: bool decode_32bit(uint32_t field_id, Proto32Bit value) override; bool decode_length(uint32_t field_id, ProtoLengthDelimited value) override; - bool decode_varint(uint32_t field_id, ProtoVarInt value) override; + bool decode_varint(uint32_t field_id, ProtoVarIntResult value) override; }; #endif #ifdef USE_SENSOR @@ -936,7 +936,7 @@ class SwitchCommandRequest final : public CommandProtoMessage { protected: bool decode_32bit(uint32_t field_id, Proto32Bit value) override; - bool decode_varint(uint32_t field_id, ProtoVarInt value) override; + bool decode_varint(uint32_t field_id, ProtoVarIntResult value) override; }; #endif #ifdef USE_TEXT_SENSOR @@ -988,7 +988,7 @@ class SubscribeLogsRequest final : public ProtoDecodableMessage { #endif protected: - bool decode_varint(uint32_t field_id, ProtoVarInt value) override; + bool decode_varint(uint32_t field_id, ProtoVarIntResult value) override; }; class SubscribeLogsResponse final : public ProtoMessage { public: @@ -1110,7 +1110,7 @@ class HomeassistantActionResponse final : public ProtoDecodableMessage { protected: bool decode_length(uint32_t field_id, ProtoLengthDelimited value) override; - bool decode_varint(uint32_t field_id, ProtoVarInt value) override; + bool decode_varint(uint32_t field_id, ProtoVarIntResult value) override; }; #endif #ifdef USE_API_HOMEASSISTANT_STATES @@ -1176,7 +1176,7 @@ class DSTRule final : public ProtoDecodableMessage { #endif protected: - bool decode_varint(uint32_t field_id, ProtoVarInt value) override; + bool decode_varint(uint32_t field_id, ProtoVarIntResult value) override; }; class ParsedTimezone final : public ProtoDecodableMessage { public: @@ -1190,7 +1190,7 @@ class ParsedTimezone final : public ProtoDecodableMessage { protected: bool decode_length(uint32_t field_id, ProtoLengthDelimited value) override; - bool decode_varint(uint32_t field_id, ProtoVarInt value) override; + bool decode_varint(uint32_t field_id, ProtoVarIntResult value) override; }; class GetTimeResponse final : public ProtoDecodableMessage { public: @@ -1261,7 +1261,7 @@ class ExecuteServiceArgument final : public ProtoDecodableMessage { protected: bool decode_32bit(uint32_t field_id, Proto32Bit value) override; bool decode_length(uint32_t field_id, ProtoLengthDelimited value) override; - bool decode_varint(uint32_t field_id, ProtoVarInt value) override; + bool decode_varint(uint32_t field_id, ProtoVarIntResult value) override; }; class ExecuteServiceRequest final : public ProtoDecodableMessage { public: @@ -1286,7 +1286,7 @@ class ExecuteServiceRequest final : public ProtoDecodableMessage { protected: bool decode_32bit(uint32_t field_id, Proto32Bit value) override; bool decode_length(uint32_t field_id, ProtoLengthDelimited value) override; - bool decode_varint(uint32_t field_id, ProtoVarInt value) override; + bool decode_varint(uint32_t field_id, ProtoVarIntResult value) override; }; #endif #ifdef USE_API_USER_DEFINED_ACTION_RESPONSES @@ -1365,7 +1365,7 @@ class CameraImageRequest final : public ProtoDecodableMessage { #endif protected: - bool decode_varint(uint32_t field_id, ProtoVarInt value) override; + bool decode_varint(uint32_t field_id, ProtoVarIntResult value) override; }; #endif #ifdef USE_CLIMATE @@ -1464,7 +1464,7 @@ class ClimateCommandRequest final : public CommandProtoMessage { protected: bool decode_32bit(uint32_t field_id, Proto32Bit value) override; bool decode_length(uint32_t field_id, ProtoLengthDelimited value) override; - bool decode_varint(uint32_t field_id, ProtoVarInt value) override; + bool decode_varint(uint32_t field_id, ProtoVarIntResult value) override; }; #endif #ifdef USE_WATER_HEATER @@ -1528,7 +1528,7 @@ class WaterHeaterCommandRequest final : public CommandProtoMessage { protected: bool decode_32bit(uint32_t field_id, Proto32Bit value) override; - bool decode_varint(uint32_t field_id, ProtoVarInt value) override; + bool decode_varint(uint32_t field_id, ProtoVarIntResult value) override; }; #endif #ifdef USE_NUMBER @@ -1584,7 +1584,7 @@ class NumberCommandRequest final : public CommandProtoMessage { protected: bool decode_32bit(uint32_t field_id, Proto32Bit value) override; - bool decode_varint(uint32_t field_id, ProtoVarInt value) override; + bool decode_varint(uint32_t field_id, ProtoVarIntResult value) override; }; #endif #ifdef USE_SELECT @@ -1636,7 +1636,7 @@ class SelectCommandRequest final : public CommandProtoMessage { protected: bool decode_32bit(uint32_t field_id, Proto32Bit value) override; bool decode_length(uint32_t field_id, ProtoLengthDelimited value) override; - bool decode_varint(uint32_t field_id, ProtoVarInt value) override; + bool decode_varint(uint32_t field_id, ProtoVarIntResult value) override; }; #endif #ifdef USE_SIREN @@ -1696,7 +1696,7 @@ class SirenCommandRequest final : public CommandProtoMessage { protected: bool decode_32bit(uint32_t field_id, Proto32Bit value) override; bool decode_length(uint32_t field_id, ProtoLengthDelimited value) override; - bool decode_varint(uint32_t field_id, ProtoVarInt value) override; + bool decode_varint(uint32_t field_id, ProtoVarIntResult value) override; }; #endif #ifdef USE_LOCK @@ -1752,7 +1752,7 @@ class LockCommandRequest final : public CommandProtoMessage { protected: bool decode_32bit(uint32_t field_id, Proto32Bit value) override; bool decode_length(uint32_t field_id, ProtoLengthDelimited value) override; - bool decode_varint(uint32_t field_id, ProtoVarInt value) override; + bool decode_varint(uint32_t field_id, ProtoVarIntResult value) override; }; #endif #ifdef USE_BUTTON @@ -1785,7 +1785,7 @@ class ButtonCommandRequest final : public CommandProtoMessage { protected: bool decode_32bit(uint32_t field_id, Proto32Bit value) override; - bool decode_varint(uint32_t field_id, ProtoVarInt value) override; + bool decode_varint(uint32_t field_id, ProtoVarIntResult value) override; }; #endif #ifdef USE_MEDIA_PLAYER @@ -1862,7 +1862,7 @@ class MediaPlayerCommandRequest final : public CommandProtoMessage { protected: bool decode_32bit(uint32_t field_id, Proto32Bit value) override; bool decode_length(uint32_t field_id, ProtoLengthDelimited value) override; - bool decode_varint(uint32_t field_id, ProtoVarInt value) override; + bool decode_varint(uint32_t field_id, ProtoVarIntResult value) override; }; #endif #ifdef USE_BLUETOOTH_PROXY @@ -1879,7 +1879,7 @@ class SubscribeBluetoothLEAdvertisementsRequest final : public ProtoDecodableMes #endif protected: - bool decode_varint(uint32_t field_id, ProtoVarInt value) override; + bool decode_varint(uint32_t field_id, ProtoVarIntResult value) override; }; class BluetoothLERawAdvertisement final : public ProtoMessage { public: @@ -1929,7 +1929,7 @@ class BluetoothDeviceRequest final : public ProtoDecodableMessage { #endif protected: - bool decode_varint(uint32_t field_id, ProtoVarInt value) override; + bool decode_varint(uint32_t field_id, ProtoVarIntResult value) override; }; class BluetoothDeviceConnectionResponse final : public ProtoMessage { public: @@ -1963,7 +1963,7 @@ class BluetoothGATTGetServicesRequest final : public ProtoDecodableMessage { #endif protected: - bool decode_varint(uint32_t field_id, ProtoVarInt value) override; + bool decode_varint(uint32_t field_id, ProtoVarIntResult value) override; }; class BluetoothGATTDescriptor final : public ProtoMessage { public: @@ -2054,7 +2054,7 @@ class BluetoothGATTReadRequest final : public ProtoDecodableMessage { #endif protected: - bool decode_varint(uint32_t field_id, ProtoVarInt value) override; + bool decode_varint(uint32_t field_id, ProtoVarIntResult value) override; }; class BluetoothGATTReadResponse final : public ProtoMessage { public: @@ -2097,7 +2097,7 @@ class BluetoothGATTWriteRequest final : public ProtoDecodableMessage { protected: bool decode_length(uint32_t field_id, ProtoLengthDelimited value) override; - bool decode_varint(uint32_t field_id, ProtoVarInt value) override; + bool decode_varint(uint32_t field_id, ProtoVarIntResult value) override; }; class BluetoothGATTReadDescriptorRequest final : public ProtoDecodableMessage { public: @@ -2113,7 +2113,7 @@ class BluetoothGATTReadDescriptorRequest final : public ProtoDecodableMessage { #endif protected: - bool decode_varint(uint32_t field_id, ProtoVarInt value) override; + bool decode_varint(uint32_t field_id, ProtoVarIntResult value) override; }; class BluetoothGATTWriteDescriptorRequest final : public ProtoDecodableMessage { public: @@ -2132,7 +2132,7 @@ class BluetoothGATTWriteDescriptorRequest final : public ProtoDecodableMessage { protected: bool decode_length(uint32_t field_id, ProtoLengthDelimited value) override; - bool decode_varint(uint32_t field_id, ProtoVarInt value) override; + bool decode_varint(uint32_t field_id, ProtoVarIntResult value) override; }; class BluetoothGATTNotifyRequest final : public ProtoDecodableMessage { public: @@ -2149,7 +2149,7 @@ class BluetoothGATTNotifyRequest final : public ProtoDecodableMessage { #endif protected: - bool decode_varint(uint32_t field_id, ProtoVarInt value) override; + bool decode_varint(uint32_t field_id, ProtoVarIntResult value) override; }; class BluetoothGATTNotifyDataResponse final : public ProtoMessage { public: @@ -2329,7 +2329,7 @@ class BluetoothScannerSetModeRequest final : public ProtoDecodableMessage { #endif protected: - bool decode_varint(uint32_t field_id, ProtoVarInt value) override; + bool decode_varint(uint32_t field_id, ProtoVarIntResult value) override; }; #endif #ifdef USE_VOICE_ASSISTANT @@ -2347,7 +2347,7 @@ class SubscribeVoiceAssistantRequest final : public ProtoDecodableMessage { #endif protected: - bool decode_varint(uint32_t field_id, ProtoVarInt value) override; + bool decode_varint(uint32_t field_id, ProtoVarIntResult value) override; }; class VoiceAssistantAudioSettings final : public ProtoMessage { public: @@ -2396,7 +2396,7 @@ class VoiceAssistantResponse final : public ProtoDecodableMessage { #endif protected: - bool decode_varint(uint32_t field_id, ProtoVarInt value) override; + bool decode_varint(uint32_t field_id, ProtoVarIntResult value) override; }; class VoiceAssistantEventData final : public ProtoDecodableMessage { public: @@ -2424,7 +2424,7 @@ class VoiceAssistantEventResponse final : public ProtoDecodableMessage { protected: bool decode_length(uint32_t field_id, ProtoLengthDelimited value) override; - bool decode_varint(uint32_t field_id, ProtoVarInt value) override; + bool decode_varint(uint32_t field_id, ProtoVarIntResult value) override; }; class VoiceAssistantAudio final : public ProtoDecodableMessage { public: @@ -2444,7 +2444,7 @@ class VoiceAssistantAudio final : public ProtoDecodableMessage { protected: bool decode_length(uint32_t field_id, ProtoLengthDelimited value) override; - bool decode_varint(uint32_t field_id, ProtoVarInt value) override; + bool decode_varint(uint32_t field_id, ProtoVarIntResult value) override; }; class VoiceAssistantTimerEventResponse final : public ProtoDecodableMessage { public: @@ -2465,7 +2465,7 @@ class VoiceAssistantTimerEventResponse final : public ProtoDecodableMessage { protected: bool decode_length(uint32_t field_id, ProtoLengthDelimited value) override; - bool decode_varint(uint32_t field_id, ProtoVarInt value) override; + bool decode_varint(uint32_t field_id, ProtoVarIntResult value) override; }; class VoiceAssistantAnnounceRequest final : public ProtoDecodableMessage { public: @@ -2484,7 +2484,7 @@ class VoiceAssistantAnnounceRequest final : public ProtoDecodableMessage { protected: bool decode_length(uint32_t field_id, ProtoLengthDelimited value) override; - bool decode_varint(uint32_t field_id, ProtoVarInt value) override; + bool decode_varint(uint32_t field_id, ProtoVarIntResult value) override; }; class VoiceAssistantAnnounceFinished final : public ProtoMessage { public: @@ -2530,7 +2530,7 @@ class VoiceAssistantExternalWakeWord final : public ProtoDecodableMessage { protected: bool decode_length(uint32_t field_id, ProtoLengthDelimited value) override; - bool decode_varint(uint32_t field_id, ProtoVarInt value) override; + bool decode_varint(uint32_t field_id, ProtoVarIntResult value) override; }; class VoiceAssistantConfigurationRequest final : public ProtoDecodableMessage { public: @@ -2632,7 +2632,7 @@ class AlarmControlPanelCommandRequest final : public CommandProtoMessage { protected: bool decode_32bit(uint32_t field_id, Proto32Bit value) override; bool decode_length(uint32_t field_id, ProtoLengthDelimited value) override; - bool decode_varint(uint32_t field_id, ProtoVarInt value) override; + bool decode_varint(uint32_t field_id, ProtoVarIntResult value) override; }; #endif #ifdef USE_TEXT @@ -2687,7 +2687,7 @@ class TextCommandRequest final : public CommandProtoMessage { protected: bool decode_32bit(uint32_t field_id, Proto32Bit value) override; bool decode_length(uint32_t field_id, ProtoLengthDelimited value) override; - bool decode_varint(uint32_t field_id, ProtoVarInt value) override; + bool decode_varint(uint32_t field_id, ProtoVarIntResult value) override; }; #endif #ifdef USE_DATETIME_DATE @@ -2741,7 +2741,7 @@ class DateCommandRequest final : public CommandProtoMessage { protected: bool decode_32bit(uint32_t field_id, Proto32Bit value) override; - bool decode_varint(uint32_t field_id, ProtoVarInt value) override; + bool decode_varint(uint32_t field_id, ProtoVarIntResult value) override; }; #endif #ifdef USE_DATETIME_TIME @@ -2795,7 +2795,7 @@ class TimeCommandRequest final : public CommandProtoMessage { protected: bool decode_32bit(uint32_t field_id, Proto32Bit value) override; - bool decode_varint(uint32_t field_id, ProtoVarInt value) override; + bool decode_varint(uint32_t field_id, ProtoVarIntResult value) override; }; #endif #ifdef USE_EVENT @@ -2886,7 +2886,7 @@ class ValveCommandRequest final : public CommandProtoMessage { protected: bool decode_32bit(uint32_t field_id, Proto32Bit value) override; - bool decode_varint(uint32_t field_id, ProtoVarInt value) override; + bool decode_varint(uint32_t field_id, ProtoVarIntResult value) override; }; #endif #ifdef USE_DATETIME_DATETIME @@ -2936,7 +2936,7 @@ class DateTimeCommandRequest final : public CommandProtoMessage { protected: bool decode_32bit(uint32_t field_id, Proto32Bit value) override; - bool decode_varint(uint32_t field_id, ProtoVarInt value) override; + bool decode_varint(uint32_t field_id, ProtoVarIntResult value) override; }; #endif #ifdef USE_UPDATE @@ -2994,7 +2994,7 @@ class UpdateCommandRequest final : public CommandProtoMessage { protected: bool decode_32bit(uint32_t field_id, Proto32Bit value) override; - bool decode_varint(uint32_t field_id, ProtoVarInt value) override; + bool decode_varint(uint32_t field_id, ProtoVarIntResult value) override; }; #endif #ifdef USE_ZWAVE_PROXY @@ -3034,7 +3034,7 @@ class ZWaveProxyRequest final : public ProtoDecodableMessage { protected: bool decode_length(uint32_t field_id, ProtoLengthDelimited value) override; - bool decode_varint(uint32_t field_id, ProtoVarInt value) override; + bool decode_varint(uint32_t field_id, ProtoVarIntResult value) override; }; #endif #ifdef USE_INFRARED @@ -3079,7 +3079,7 @@ class InfraredRFTransmitRawTimingsRequest final : public ProtoDecodableMessage { protected: bool decode_32bit(uint32_t field_id, Proto32Bit value) override; bool decode_length(uint32_t field_id, ProtoLengthDelimited value) override; - bool decode_varint(uint32_t field_id, ProtoVarInt value) override; + bool decode_varint(uint32_t field_id, ProtoVarIntResult value) override; }; class InfraredRFReceiveEvent final : public ProtoMessage { public: @@ -3121,7 +3121,7 @@ class SerialProxyConfigureRequest final : public ProtoDecodableMessage { #endif protected: - bool decode_varint(uint32_t field_id, ProtoVarInt value) override; + bool decode_varint(uint32_t field_id, ProtoVarIntResult value) override; }; class SerialProxyDataReceived final : public ProtoMessage { public: @@ -3161,7 +3161,7 @@ class SerialProxyWriteRequest final : public ProtoDecodableMessage { protected: bool decode_length(uint32_t field_id, ProtoLengthDelimited value) override; - bool decode_varint(uint32_t field_id, ProtoVarInt value) override; + bool decode_varint(uint32_t field_id, ProtoVarIntResult value) override; }; class SerialProxySetModemPinsRequest final : public ProtoDecodableMessage { public: @@ -3177,7 +3177,7 @@ class SerialProxySetModemPinsRequest final : public ProtoDecodableMessage { #endif protected: - bool decode_varint(uint32_t field_id, ProtoVarInt value) override; + bool decode_varint(uint32_t field_id, ProtoVarIntResult value) override; }; class SerialProxyGetModemPinsRequest final : public ProtoDecodableMessage { public: @@ -3192,7 +3192,7 @@ class SerialProxyGetModemPinsRequest final : public ProtoDecodableMessage { #endif protected: - bool decode_varint(uint32_t field_id, ProtoVarInt value) override; + bool decode_varint(uint32_t field_id, ProtoVarIntResult value) override; }; class SerialProxyGetModemPinsResponse final : public ProtoMessage { public: @@ -3225,7 +3225,7 @@ class SerialProxyRequest final : public ProtoDecodableMessage { #endif protected: - bool decode_varint(uint32_t field_id, ProtoVarInt value) override; + bool decode_varint(uint32_t field_id, ProtoVarIntResult value) override; }; class SerialProxyRequestResponse final : public ProtoMessage { public: @@ -3265,7 +3265,7 @@ class BluetoothSetConnectionParamsRequest final : public ProtoDecodableMessage { #endif protected: - bool decode_varint(uint32_t field_id, ProtoVarInt value) override; + bool decode_varint(uint32_t field_id, ProtoVarIntResult value) override; }; class BluetoothSetConnectionParamsResponse final : public ProtoMessage { public: diff --git a/esphome/components/api/proto.cpp b/esphome/components/api/proto.cpp index fb229928e5..dd682fddd4 100644 --- a/esphome/components/api/proto.cpp +++ b/esphome/components/api/proto.cpp @@ -20,20 +20,40 @@ void ProtoWriteBuffer::encode_varint_raw_slow_(uint32_t value) { *this->pos_++ = static_cast(value); } +ProtoVarIntResult ProtoVarInt::parse_slow_(const uint8_t *buffer, uint32_t len) { + // Multi-byte varint: first byte already checked to have high bit set + uint32_t result32 = buffer[0] & 0x7F; #ifdef USE_API_VARINT64 -optional ProtoVarInt::parse_wide(const uint8_t *buffer, uint32_t len, uint32_t *consumed, - uint32_t result32) { + uint32_t limit = std::min(len, uint32_t(4)); +#else + uint32_t limit = std::min(len, uint32_t(5)); +#endif + for (uint32_t i = 1; i < limit; i++) { + uint8_t val = buffer[i]; + result32 |= uint32_t(val & 0x7F) << (i * 7); + if ((val & 0x80) == 0) { + return {result32, i + 1}; + } + } +#ifdef USE_API_VARINT64 + return parse_wide_(buffer, len, result32); +#else + return {0, 0}; +#endif +} + +#ifdef USE_API_VARINT64 +ProtoVarIntResult ProtoVarInt::parse_wide_(const uint8_t *buffer, uint32_t len, uint32_t result32) { uint64_t result64 = result32; uint32_t limit = std::min(len, uint32_t(10)); for (uint32_t i = 4; i < limit; i++) { uint8_t val = buffer[i]; result64 |= uint64_t(val & 0x7F) << (i * 7); if ((val & 0x80) == 0) { - *consumed = i + 1; - return ProtoVarInt(result64); + return {result64, i + 1}; } } - return {}; + return {0, 0}; } #endif @@ -43,18 +63,16 @@ uint32_t ProtoDecodableMessage::count_repeated_field(const uint8_t *buffer, size const uint8_t *end = buffer + length; while (ptr < end) { - uint32_t consumed; - // Parse field header (tag) - auto res = ProtoVarInt::parse(ptr, end - ptr, &consumed); + auto res = ProtoVarInt::parse(ptr, end - ptr); if (!res.has_value()) { break; // Invalid data, stop counting } - uint32_t tag = res->as_uint32(); + uint32_t tag = res.as_uint32(); uint32_t field_type = tag & WIRE_TYPE_MASK; uint32_t field_id = tag >> 3; - ptr += consumed; + ptr += res.consumed; // Count if this is the target field if (field_id == target_field_id) { @@ -64,20 +82,20 @@ uint32_t ProtoDecodableMessage::count_repeated_field(const uint8_t *buffer, size // Skip field data based on wire type switch (field_type) { case WIRE_TYPE_VARINT: { // VarInt - parse and skip - res = ProtoVarInt::parse(ptr, end - ptr, &consumed); + res = ProtoVarInt::parse(ptr, end - ptr); if (!res.has_value()) { return count; // Invalid data, return what we have } - ptr += consumed; + ptr += res.consumed; break; } case WIRE_TYPE_LENGTH_DELIMITED: { // Length-delimited - parse length and skip data - res = ProtoVarInt::parse(ptr, end - ptr, &consumed); + res = ProtoVarInt::parse(ptr, end - ptr); if (!res.has_value()) { return count; } - uint32_t field_length = res->as_uint32(); - ptr += consumed; + uint32_t field_length = res.as_uint32(); + ptr += res.consumed; if (field_length > static_cast(end - ptr)) { return count; // Out of bounds } @@ -190,41 +208,39 @@ void ProtoDecodableMessage::decode(const uint8_t *buffer, size_t length) { const uint8_t *end = buffer + length; while (ptr < end) { - uint32_t consumed; - // Parse field header - auto res = ProtoVarInt::parse(ptr, end - ptr, &consumed); + auto res = ProtoVarInt::parse(ptr, end - ptr); if (!res.has_value()) { ESP_LOGV(TAG, "Invalid field start at offset %ld", (long) (ptr - buffer)); return; } - uint32_t tag = res->as_uint32(); + uint32_t tag = res.as_uint32(); uint32_t field_type = tag & WIRE_TYPE_MASK; uint32_t field_id = tag >> 3; - ptr += consumed; + ptr += res.consumed; switch (field_type) { case WIRE_TYPE_VARINT: { // VarInt - res = ProtoVarInt::parse(ptr, end - ptr, &consumed); + res = ProtoVarInt::parse(ptr, end - ptr); if (!res.has_value()) { ESP_LOGV(TAG, "Invalid VarInt at offset %ld", (long) (ptr - buffer)); return; } - if (!this->decode_varint(field_id, *res)) { - ESP_LOGV(TAG, "Cannot decode VarInt field %" PRIu32 " with value %" PRIu32 "!", field_id, res->as_uint32()); + if (!this->decode_varint(field_id, res)) { + ESP_LOGV(TAG, "Cannot decode VarInt field %" PRIu32 " with value %" PRIu32 "!", field_id, res.as_uint32()); } - ptr += consumed; + ptr += res.consumed; break; } case WIRE_TYPE_LENGTH_DELIMITED: { // Length-delimited - res = ProtoVarInt::parse(ptr, end - ptr, &consumed); + res = ProtoVarInt::parse(ptr, end - ptr); if (!res.has_value()) { ESP_LOGV(TAG, "Invalid Length Delimited at offset %ld", (long) (ptr - buffer)); return; } - uint32_t field_length = res->as_uint32(); - ptr += consumed; + uint32_t field_length = res.as_uint32(); + ptr += res.consumed; if (field_length > static_cast(end - ptr)) { ESP_LOGV(TAG, "Out-of-bounds Length Delimited at offset %ld", (long) (ptr - buffer)); return; diff --git a/esphome/components/api/proto.h b/esphome/components/api/proto.h index adde0a8a85..2cd8f286b2 100644 --- a/esphome/components/api/proto.h +++ b/esphome/components/api/proto.h @@ -98,62 +98,57 @@ inline void encode_varint_to_buffer(uint32_t val, uint8_t *buffer) { * within the same function scope where temporaries are created. */ +/// Result of parsing a varint: value + number of bytes consumed. +/// consumed == 0 indicates parse failure (not enough data or invalid). +struct ProtoVarIntResult { +#ifdef USE_API_VARINT64 + uint64_t value; +#else + uint32_t value; +#endif + uint32_t consumed; // 0 = parse failed + + constexpr bool has_value() const { return this->consumed != 0; } + constexpr uint16_t as_uint16() const { return this->value; } + constexpr uint32_t as_uint32() const { return this->value; } + constexpr bool as_bool() const { return this->value; } + constexpr int32_t as_int32() const { return static_cast(this->value); } + constexpr int32_t as_sint32() const { return decode_zigzag32(static_cast(this->value)); } +#ifdef USE_API_VARINT64 + constexpr uint64_t as_uint64() const { return this->value; } + constexpr int64_t as_int64() const { return static_cast(this->value); } + constexpr int64_t as_sint64() const { return decode_zigzag64(this->value); } +#endif +}; + /// Representation of a VarInt - in ProtoBuf should be 64bit but we only use 32bit class ProtoVarInt { public: ProtoVarInt() : value_(0) {} explicit ProtoVarInt(uint64_t value) : value_(value) {} - /// Parse a varint from buffer. consumed must be a valid pointer (not null). - static optional parse(const uint8_t *buffer, uint32_t len, uint32_t *consumed) { -#ifdef ESPHOME_DEBUG_API - assert(consumed != nullptr); -#endif + /// Parse a varint from buffer. Returns result with consumed=0 on failure. + static inline ProtoVarIntResult ESPHOME_ALWAYS_INLINE parse(const uint8_t *buffer, uint32_t len) { if (len == 0) - return {}; + return {0, 0}; // Fast path: single-byte varints (0-127) are the most common case - // (booleans, small enums, field tags). Avoid loop overhead entirely. - if ((buffer[0] & 0x80) == 0) { - *consumed = 1; - return ProtoVarInt(buffer[0]); - } - // 32-bit phase: process remaining bytes with native 32-bit shifts. - // Without USE_API_VARINT64: cover bytes 1-4 (shifts 7, 14, 21, 28) — the uint32_t - // shift at byte 4 (shift by 28) may lose bits 32-34, but those are always zero for valid uint32 values. - // With USE_API_VARINT64: cover bytes 1-3 (shifts 7, 14, 21) so parse_wide handles - // byte 4+ with full 64-bit arithmetic (avoids truncating values > UINT32_MAX). - uint32_t result32 = buffer[0] & 0x7F; -#ifdef USE_API_VARINT64 - uint32_t limit = std::min(len, uint32_t(4)); -#else - uint32_t limit = std::min(len, uint32_t(5)); -#endif - for (uint32_t i = 1; i < limit; i++) { - uint8_t val = buffer[i]; - result32 |= uint32_t(val & 0x7F) << (i * 7); - if ((val & 0x80) == 0) { - *consumed = i + 1; - return ProtoVarInt(result32); - } - } - // 64-bit phase for remaining bytes (BLE addresses etc.) -#ifdef USE_API_VARINT64 - return parse_wide(buffer, len, consumed, result32); -#else - return {}; -#endif + // (booleans, small enums, field tags, small message sizes/types). + if ((buffer[0] & 0x80) == 0) [[likely]] + return {buffer[0], 1}; + return parse_slow_(buffer, len); } -#ifdef USE_API_VARINT64 protected: - /// Continue parsing varint bytes 4-9 with 64-bit arithmetic. - /// Separated to keep 64-bit shift code (__ashldi3 on 32-bit platforms) out of the common path. - static optional parse_wide(const uint8_t *buffer, uint32_t len, uint32_t *consumed, uint32_t result32) - __attribute__((noinline)); + // Slow path for multi-byte varints (>= 128), outlined to keep fast path small + static ProtoVarIntResult parse_slow_(const uint8_t *buffer, uint32_t len) __attribute__((noinline)); - public: +#ifdef USE_API_VARINT64 + /// Continue parsing varint bytes 4-9 with 64-bit arithmetic. + static ProtoVarIntResult parse_wide_(const uint8_t *buffer, uint32_t len, uint32_t result32) + __attribute__((noinline)); #endif + public: constexpr uint16_t as_uint16() const { return this->value_; } constexpr uint32_t as_uint32() const { return this->value_; } constexpr bool as_bool() const { return this->value_; } @@ -499,7 +494,7 @@ class ProtoDecodableMessage : public ProtoMessage { protected: ~ProtoDecodableMessage() = default; - virtual bool decode_varint(uint32_t field_id, ProtoVarInt value) { return false; } + virtual bool decode_varint(uint32_t field_id, ProtoVarIntResult value) { return false; } virtual bool decode_length(uint32_t field_id, ProtoLengthDelimited value) { return false; } virtual bool decode_32bit(uint32_t field_id, Proto32Bit value) { return false; } // NOTE: decode_64bit removed - wire type 1 not supported diff --git a/script/api_protobuf/api_protobuf.py b/script/api_protobuf/api_protobuf.py index 206f8f558b..bf1d34d67f 100755 --- a/script/api_protobuf/api_protobuf.py +++ b/script/api_protobuf/api_protobuf.py @@ -2205,7 +2205,7 @@ def build_message_type( cpp = "" if decode_varint: - o = f"bool {desc.name}::decode_varint(uint32_t field_id, ProtoVarInt value) {{\n" + o = f"bool {desc.name}::decode_varint(uint32_t field_id, ProtoVarIntResult value) {{\n" o += " switch (field_id) {\n" o += indent("\n".join(decode_varint), " ") + "\n" o += " default: return false;\n" @@ -2213,7 +2213,9 @@ def build_message_type( o += " return true;\n" o += "}\n" cpp += o - prot = "bool decode_varint(uint32_t field_id, ProtoVarInt value) override;" + prot = ( + "bool decode_varint(uint32_t field_id, ProtoVarIntResult value) override;" + ) protected_content.insert(0, prot) if decode_length: o = f"bool {desc.name}::decode_length(uint32_t field_id, ProtoLengthDelimited value) {{\n" From 5d3893368d003a0904554e9170a1645f5c687efe Mon Sep 17 00:00:00 2001 From: Jonathan Swoboda <154711427+swoboda1337@users.noreply.github.com> Date: Sun, 8 Mar 2026 23:16:32 -0400 Subject: [PATCH 02/15] [multiple] Add array bounds checks (#14635) Co-authored-by: Claude Opus 4.6 --- .../addressable_light/addressable_light_display.cpp | 5 ++++- esphome/components/bme680_bsec/bme680_bsec.cpp | 2 +- esphome/components/bme68x_bsec2/bme68x_bsec2.cpp | 1 + esphome/components/dac7678/dac7678_output.cpp | 2 ++ esphome/components/seeed_mr24hpc1/seeed_mr24hpc1.cpp | 5 +++-- esphome/components/seeed_mr60fda2/seeed_mr60fda2.cpp | 6 ++++++ 6 files changed, 17 insertions(+), 4 deletions(-) diff --git a/esphome/components/addressable_light/addressable_light_display.cpp b/esphome/components/addressable_light/addressable_light_display.cpp index 16fab15b17..329620bcf0 100644 --- a/esphome/components/addressable_light/addressable_light_display.cpp +++ b/esphome/components/addressable_light/addressable_light_display.cpp @@ -58,7 +58,10 @@ void HOT AddressableLightDisplay::draw_absolute_pixel_internal(int x, int y, Col if (this->pixel_mapper_f_.has_value()) { // Params are passed by reference, so they may be modified in call. - this->addressable_light_buffer_[(*this->pixel_mapper_f_)(x, y)] = color; + int index = (*this->pixel_mapper_f_)(x, y); + if (index < 0 || static_cast(index) >= this->addressable_light_buffer_.size()) + return; + this->addressable_light_buffer_[index] = color; } else { this->addressable_light_buffer_[y * this->get_width_internal() + x] = color; } diff --git a/esphome/components/bme680_bsec/bme680_bsec.cpp b/esphome/components/bme680_bsec/bme680_bsec.cpp index 392d071b31..454be0c0fe 100644 --- a/esphome/components/bme680_bsec/bme680_bsec.cpp +++ b/esphome/components/bme680_bsec/bme680_bsec.cpp @@ -383,7 +383,7 @@ void BME680BSECComponent::publish_(const bsec_output_t *outputs, uint8_t num_out switch (outputs[i].sensor_id) { case BSEC_OUTPUT_IAQ: case BSEC_OUTPUT_STATIC_IAQ: { - uint8_t accuracy = outputs[i].accuracy; + uint8_t accuracy = std::min(outputs[i].accuracy, std::size(IAQ_ACCURACY_STATES) - 1); this->queue_push_([this, signal]() { this->publish_sensor_(this->iaq_sensor_, signal); }); this->queue_push_([this, accuracy]() { this->publish_sensor_(this->iaq_accuracy_text_sensor_, IAQ_ACCURACY_STATES[accuracy]); diff --git a/esphome/components/bme68x_bsec2/bme68x_bsec2.cpp b/esphome/components/bme68x_bsec2/bme68x_bsec2.cpp index 1a42c9d54b..0210d1e67d 100644 --- a/esphome/components/bme68x_bsec2/bme68x_bsec2.cpp +++ b/esphome/components/bme68x_bsec2/bme68x_bsec2.cpp @@ -438,6 +438,7 @@ void BME68xBSEC2Component::publish_(const bsec_output_t *outputs, uint8_t num_ou } } if (update_accuracy) { + max_accuracy = std::min(max_accuracy, std::size(IAQ_ACCURACY_STATES) - 1); #ifdef USE_SENSOR this->queue_push_( [this, max_accuracy]() { this->publish_sensor_(this->iaq_accuracy_sensor_, max_accuracy, true); }); diff --git a/esphome/components/dac7678/dac7678_output.cpp b/esphome/components/dac7678/dac7678_output.cpp index 83f8722e7f..27ab54f0be 100644 --- a/esphome/components/dac7678/dac7678_output.cpp +++ b/esphome/components/dac7678/dac7678_output.cpp @@ -62,6 +62,8 @@ void DAC7678Output::register_channel(DAC7678Channel *channel) { } void DAC7678Output::set_channel_value_(uint8_t channel, uint16_t value) { + if (channel >= std::size(this->dac_input_reg_)) + return; if (this->dac_input_reg_[channel] != value) { ESP_LOGV(TAG, "Channel %01u: input_reg=%04u ", channel, value); diff --git a/esphome/components/seeed_mr24hpc1/seeed_mr24hpc1.cpp b/esphome/components/seeed_mr24hpc1/seeed_mr24hpc1.cpp index 99d519b434..263603704a 100644 --- a/esphome/components/seeed_mr24hpc1/seeed_mr24hpc1.cpp +++ b/esphome/components/seeed_mr24hpc1/seeed_mr24hpc1.cpp @@ -452,7 +452,8 @@ void MR24HPC1Component::r24_frame_parse_open_underlying_information_(uint8_t *da } break; case 0x83: - if (this->custom_presence_of_detection_sensor_ != nullptr) { + if (this->custom_presence_of_detection_sensor_ != nullptr && + data[FRAME_DATA_INDEX] < std::size(S_PRESENCE_OF_DETECTION_RANGE_STR)) { this->custom_presence_of_detection_sensor_->publish_state( S_PRESENCE_OF_DETECTION_RANGE_STR[data[FRAME_DATA_INDEX]]); } @@ -646,7 +647,7 @@ void MR24HPC1Component::r24_frame_parse_human_information_(uint8_t *data) { #ifdef USE_BINARY_SENSOR case 0x01: case 0x81: - if (this->has_target_binary_sensor_ != nullptr) { + if (this->has_target_binary_sensor_ != nullptr && data[FRAME_DATA_INDEX] < std::size(S_SOMEONE_EXISTS_STR)) { this->has_target_binary_sensor_->publish_state(S_SOMEONE_EXISTS_STR[data[FRAME_DATA_INDEX]]); } break; diff --git a/esphome/components/seeed_mr60fda2/seeed_mr60fda2.cpp b/esphome/components/seeed_mr60fda2/seeed_mr60fda2.cpp index c6527a948e..e24e9b338e 100644 --- a/esphome/components/seeed_mr60fda2/seeed_mr60fda2.cpp +++ b/esphome/components/seeed_mr60fda2/seeed_mr60fda2.cpp @@ -334,6 +334,8 @@ void MR60FDA2Component::process_frame_() { // Send Heartbeat Packet Command void MR60FDA2Component::set_install_height(uint8_t index) { + if (index >= std::size(INSTALL_HEIGHT)) + return; uint8_t send_data[13] = {0x01, 0x00, 0x00, 0x00, 0x04, 0x0E, 0x04, 0xF0, 0x00, 0x00, 0x00, 0x00, 0x00}; float_to_bytes(INSTALL_HEIGHT[index], &send_data[8]); send_data[12] = calculate_checksum(send_data + 8, 4); @@ -345,6 +347,8 @@ void MR60FDA2Component::set_install_height(uint8_t index) { } void MR60FDA2Component::set_height_threshold(uint8_t index) { + if (index >= std::size(HEIGHT_THRESHOLD)) + return; uint8_t send_data[13] = {0x01, 0x00, 0x00, 0x00, 0x04, 0x0E, 0x08, 0xFC, 0x00, 0x00, 0x00, 0x00, 0x00}; float_to_bytes(HEIGHT_THRESHOLD[index], &send_data[8]); send_data[12] = calculate_checksum(send_data + 8, 4); @@ -356,6 +360,8 @@ void MR60FDA2Component::set_height_threshold(uint8_t index) { } void MR60FDA2Component::set_sensitivity(uint8_t index) { + if (index >= std::size(SENSITIVITY)) + return; uint8_t send_data[13] = {0x01, 0x00, 0x00, 0x00, 0x04, 0x0E, 0x0A, 0xFE, 0x00, 0x00, 0x00, 0x00, 0x00}; int_to_bytes(SENSITIVITY[index], &send_data[8]); From c90eb90ff607f920c275ba020cdeb865abb97dc2 Mon Sep 17 00:00:00 2001 From: "J. Nick Koston" Date: Sun, 8 Mar 2026 17:23:36 -1000 Subject: [PATCH 03/15] Fix clang-tidy naming and add PROTO_VARINT_PARSE_FAILED constant - Rename parse_slow_ -> parse_slow and parse_wide_ -> parse_wide (static methods should not have trailing underscore per clang-tidy) - Add PROTO_VARINT_PARSE_FAILED constant for consumed field sentinel Co-Authored-By: Claude Opus 4.6 --- esphome/components/api/proto.cpp | 6 +++--- esphome/components/api/proto.h | 16 +++++++++------- 2 files changed, 12 insertions(+), 10 deletions(-) diff --git a/esphome/components/api/proto.cpp b/esphome/components/api/proto.cpp index dd682fddd4..7e01185849 100644 --- a/esphome/components/api/proto.cpp +++ b/esphome/components/api/proto.cpp @@ -20,7 +20,7 @@ void ProtoWriteBuffer::encode_varint_raw_slow_(uint32_t value) { *this->pos_++ = static_cast(value); } -ProtoVarIntResult ProtoVarInt::parse_slow_(const uint8_t *buffer, uint32_t len) { +ProtoVarIntResult ProtoVarInt::parse_slow(const uint8_t *buffer, uint32_t len) { // Multi-byte varint: first byte already checked to have high bit set uint32_t result32 = buffer[0] & 0x7F; #ifdef USE_API_VARINT64 @@ -36,14 +36,14 @@ ProtoVarIntResult ProtoVarInt::parse_slow_(const uint8_t *buffer, uint32_t len) } } #ifdef USE_API_VARINT64 - return parse_wide_(buffer, len, result32); + return parse_wide(buffer, len, result32); #else return {0, 0}; #endif } #ifdef USE_API_VARINT64 -ProtoVarIntResult ProtoVarInt::parse_wide_(const uint8_t *buffer, uint32_t len, uint32_t result32) { +ProtoVarIntResult ProtoVarInt::parse_wide(const uint8_t *buffer, uint32_t len, uint32_t result32) { uint64_t result64 = result32; uint32_t limit = std::min(len, uint32_t(10)); for (uint32_t i = 4; i < limit; i++) { diff --git a/esphome/components/api/proto.h b/esphome/components/api/proto.h index 2cd8f286b2..04cb0cc85c 100644 --- a/esphome/components/api/proto.h +++ b/esphome/components/api/proto.h @@ -98,17 +98,20 @@ inline void encode_varint_to_buffer(uint32_t val, uint8_t *buffer) { * within the same function scope where temporaries are created. */ +/// Sentinel value for consumed field indicating parse failure +inline constexpr uint32_t PROTO_VARINT_PARSE_FAILED = 0; + /// Result of parsing a varint: value + number of bytes consumed. -/// consumed == 0 indicates parse failure (not enough data or invalid). +/// consumed == PROTO_VARINT_PARSE_FAILED indicates parse failure (not enough data or invalid). struct ProtoVarIntResult { #ifdef USE_API_VARINT64 uint64_t value; #else uint32_t value; #endif - uint32_t consumed; // 0 = parse failed + uint32_t consumed; // PROTO_VARINT_PARSE_FAILED = parse failed - constexpr bool has_value() const { return this->consumed != 0; } + constexpr bool has_value() const { return this->consumed != PROTO_VARINT_PARSE_FAILED; } constexpr uint16_t as_uint16() const { return this->value; } constexpr uint32_t as_uint32() const { return this->value; } constexpr bool as_bool() const { return this->value; } @@ -135,17 +138,16 @@ class ProtoVarInt { // (booleans, small enums, field tags, small message sizes/types). if ((buffer[0] & 0x80) == 0) [[likely]] return {buffer[0], 1}; - return parse_slow_(buffer, len); + return parse_slow(buffer, len); } protected: // Slow path for multi-byte varints (>= 128), outlined to keep fast path small - static ProtoVarIntResult parse_slow_(const uint8_t *buffer, uint32_t len) __attribute__((noinline)); + static ProtoVarIntResult parse_slow(const uint8_t *buffer, uint32_t len) __attribute__((noinline)); #ifdef USE_API_VARINT64 /// Continue parsing varint bytes 4-9 with 64-bit arithmetic. - static ProtoVarIntResult parse_wide_(const uint8_t *buffer, uint32_t len, uint32_t result32) - __attribute__((noinline)); + static ProtoVarIntResult parse_wide(const uint8_t *buffer, uint32_t len, uint32_t result32) __attribute__((noinline)); #endif public: From 088a8a4338940c061fa181b55845a5d25c6268ce Mon Sep 17 00:00:00 2001 From: "J. Nick Koston" Date: Sun, 8 Mar 2026 17:23:58 -1000 Subject: [PATCH 04/15] [ci] Match symbols with changed signatures in memory impact analysis (#14600) Co-authored-by: Claude Opus 4.6 --- script/ci_memory_impact_comment.py | 75 ++++++++++++++ tests/unit_tests/analyze_memory/__init__.py | 0 .../test_ci_memory_impact_comment.py | 99 +++++++++++++++++++ 3 files changed, 174 insertions(+) create mode 100644 tests/unit_tests/analyze_memory/__init__.py create mode 100644 tests/unit_tests/analyze_memory/test_ci_memory_impact_comment.py diff --git a/script/ci_memory_impact_comment.py b/script/ci_memory_impact_comment.py index a296130645..01316da27f 100755 --- a/script/ci_memory_impact_comment.py +++ b/script/ci_memory_impact_comment.py @@ -160,6 +160,76 @@ def format_change(before: int, after: int, threshold: float | None = None) -> st return f"{emoji} {delta_str} ({pct_str})" +def _sig_base(sym: str) -> str: + """Strip argument types from a symbol name for fuzzy matching. + + Removes the entire outermost parenthesized argument list (including + the parentheses) from the symbol string. + + This makes, for example, "foo(int)::nested" and "foo(float)::nested" + share the same key "foo::nested", while "foo(int)" maps to "foo" and + therefore does NOT collide with "foo(int)::nested". + """ + start = sym.find("(") + if start == -1: + return sym + end = sym.rfind(")") + if end == -1: + return sym + return sym[:start] + sym[end + 1 :] + + +_AMBIGUOUS = object() + + +def _match_signature_changes( + changed_symbols: list[tuple[str, int, int, int]], + new_symbols: list[tuple[str, int]], + removed_symbols: list[tuple[str, int]], +) -> tuple[ + list[tuple[str, int, int, int]], + list[tuple[str, int]], + list[tuple[str, int]], +]: + """Match new/removed symbol pairs that only differ in argument types. + + When a function's argument types change (e.g. foo(vector<>&) -> foo(Buffer&)), + it appears as a new + removed symbol. This matches them by base name and moves + them to changed_symbols. Only matches unambiguous 1:1 pairs. + """ + if not new_symbols or not removed_symbols: + return changed_symbols, new_symbols, removed_symbols + + # Build base -> entry maps; mark ambiguous bases with sentinel + new_by_base: dict[str, tuple[str, int] | object] = {} + for entry in new_symbols: + base = _sig_base(entry[0]) + new_by_base[base] = _AMBIGUOUS if base in new_by_base else entry + removed_by_base: dict[str, tuple[str, int] | object] = {} + for entry in removed_symbols: + base = _sig_base(entry[0]) + removed_by_base[base] = _AMBIGUOUS if base in removed_by_base else entry + + matched: set[str] = set() # matched base keys + for base, new_entry in new_by_base.items(): + if new_entry is _AMBIGUOUS: + continue + rem_entry = removed_by_base.get(base) + if rem_entry is None or rem_entry is _AMBIGUOUS: + continue + pr_sym, pr_size = new_entry + _rm_sym, target_size = rem_entry + delta = pr_size - target_size + if delta != 0: + changed_symbols.append((pr_sym, target_size, pr_size, delta)) + matched.add(base) + + if matched: + new_symbols = [e for e in new_symbols if _sig_base(e[0]) not in matched] + removed_symbols = [e for e in removed_symbols if _sig_base(e[0]) not in matched] + return changed_symbols, new_symbols, removed_symbols + + def prepare_symbol_changes_data( target_symbols: dict | None, pr_symbols: dict | None ) -> dict | None: @@ -200,6 +270,11 @@ def prepare_symbol_changes_data( delta = pr_size - target_size changed_symbols.append((symbol, target_size, pr_size, delta)) + # Match new/removed symbols that only differ in argument types + changed_symbols, new_symbols, removed_symbols = _match_signature_changes( + changed_symbols, new_symbols, removed_symbols + ) + if not changed_symbols and not new_symbols and not removed_symbols: return None diff --git a/tests/unit_tests/analyze_memory/__init__.py b/tests/unit_tests/analyze_memory/__init__.py new file mode 100644 index 0000000000..e69de29bb2 diff --git a/tests/unit_tests/analyze_memory/test_ci_memory_impact_comment.py b/tests/unit_tests/analyze_memory/test_ci_memory_impact_comment.py new file mode 100644 index 0000000000..8399ac0303 --- /dev/null +++ b/tests/unit_tests/analyze_memory/test_ci_memory_impact_comment.py @@ -0,0 +1,99 @@ +"""Tests for script/ci_memory_impact_comment.py symbol matching.""" + +from pathlib import Path +import sys + +# Add script directory to path so we can import the module +sys.path.insert(0, str(Path(__file__).parent.parent.parent.parent / "script")) + +from ci_memory_impact_comment import prepare_symbol_changes_data # noqa: E402 + + +def test_prepare_symbol_changes_signature_match() -> None: + """Symbols with same base name but different args are matched as changed.""" + target = { + "Foo::bar(std::vector&, int)": 300, + "unchanged()": 50, + } + pr = { + "Foo::bar(ProtoByteBuffer&, int)": 320, + "unchanged()": 50, + } + result = prepare_symbol_changes_data(target, pr) + assert result is not None + assert len(result["changed_symbols"]) == 1 + assert len(result["new_symbols"]) == 0 + assert len(result["removed_symbols"]) == 0 + sym, t_size, p_size, delta = result["changed_symbols"][0] + assert sym == "Foo::bar(ProtoByteBuffer&, int)" + assert t_size == 300 + assert p_size == 320 + assert delta == 20 + + +def test_prepare_symbol_changes_ambiguous_overloads_not_matched() -> None: + """Multiple overloads with same base name stay as new/removed.""" + target = { + "Foo::bar(int)": 100, + "Foo::bar(float)": 200, + } + pr = { + "Foo::bar(double)": 150, + "Foo::bar(long)": 250, + } + result = prepare_symbol_changes_data(target, pr) + assert result is not None + assert len(result["changed_symbols"]) == 0 + assert len(result["new_symbols"]) == 2 + assert len(result["removed_symbols"]) == 2 + + +def test_prepare_symbol_changes_no_parens_not_matched() -> None: + """Symbols without parens (variables) are not fuzzy-matched.""" + target = {"my_global_var": 100} + pr = {"my_global_var_v2": 120} + result = prepare_symbol_changes_data(target, pr) + assert result is not None + assert len(result["changed_symbols"]) == 0 + assert len(result["new_symbols"]) == 1 + assert len(result["removed_symbols"]) == 1 + + +def test_prepare_symbol_changes_nested_symbols_matched_separately() -> None: + """Nested symbols like ::__pstr__ don't collide with parent function.""" + target = { + "Foo::bar(std::vector&, int)": 300, + "Foo::bar(std::vector&, int)::__pstr__": 19, + } + pr = { + "Foo::bar(ProtoByteBuffer&, int)": 320, + "Foo::bar(ProtoByteBuffer&, int)::__pstr__": 19, + } + result = prepare_symbol_changes_data(target, pr) + assert result is not None + # Both the function and its nested __pstr__ should be matched (not new/removed) + assert len(result["new_symbols"]) == 0 + assert len(result["removed_symbols"]) == 0 + # __pstr__ has delta=0 so it's silently dropped, only the function shows + assert len(result["changed_symbols"]) == 1 + sym, t_size, p_size, delta = result["changed_symbols"][0] + assert sym == "Foo::bar(ProtoByteBuffer&, int)" + assert delta == 20 + + +def test_prepare_symbol_changes_exact_match_preferred() -> None: + """Exact name matches are found before fuzzy matching runs.""" + target = { + "Foo::bar(int)": 100, + } + pr = { + "Foo::bar(int)": 120, + } + result = prepare_symbol_changes_data(target, pr) + assert result is not None + assert len(result["changed_symbols"]) == 1 + assert len(result["new_symbols"]) == 0 + assert len(result["removed_symbols"]) == 0 + sym, t_size, p_size, delta = result["changed_symbols"][0] + assert sym == "Foo::bar(int)" + assert delta == 20 From 8b9c4d050ddb8393dd1904b04658bfe790f9c1fe Mon Sep 17 00:00:00 2001 From: "J. Nick Koston" Date: Sun, 8 Mar 2026 17:37:55 -1000 Subject: [PATCH 05/15] Reduce parse() inline size by folding len==0 into slow path Move the len==0 check from the inlined fast path into parse_slow(), saving one branch + one return-value setup per inline site (~6-8 bytes per call site on Xtensa/xtensa-lx106). Co-Authored-By: Claude Opus 4.6 --- esphome/components/api/proto.cpp | 2 ++ esphome/components/api/proto.h | 6 +++--- 2 files changed, 5 insertions(+), 3 deletions(-) diff --git a/esphome/components/api/proto.cpp b/esphome/components/api/proto.cpp index 7e01185849..4cbc8f46c2 100644 --- a/esphome/components/api/proto.cpp +++ b/esphome/components/api/proto.cpp @@ -21,6 +21,8 @@ void ProtoWriteBuffer::encode_varint_raw_slow_(uint32_t value) { } ProtoVarIntResult ProtoVarInt::parse_slow(const uint8_t *buffer, uint32_t len) { + if (len == 0) + return {0, 0}; // Multi-byte varint: first byte already checked to have high bit set uint32_t result32 = buffer[0] & 0x7F; #ifdef USE_API_VARINT64 diff --git a/esphome/components/api/proto.h b/esphome/components/api/proto.h index 04cb0cc85c..55054ed157 100644 --- a/esphome/components/api/proto.h +++ b/esphome/components/api/proto.h @@ -132,11 +132,11 @@ class ProtoVarInt { /// Parse a varint from buffer. Returns result with consumed=0 on failure. static inline ProtoVarIntResult ESPHOME_ALWAYS_INLINE parse(const uint8_t *buffer, uint32_t len) { - if (len == 0) - return {0, 0}; // Fast path: single-byte varints (0-127) are the most common case // (booleans, small enums, field tags, small message sizes/types). - if ((buffer[0] & 0x80) == 0) [[likely]] + // len==0 check is folded into the condition to minimize inline size; + // parse_slow() handles len==0. + if (len != 0 && (buffer[0] & 0x80) == 0) [[likely]] return {buffer[0], 1}; return parse_slow(buffer, len); } From 7185c66779db02ff0219be05e9d514025a86d463 Mon Sep 17 00:00:00 2001 From: "J. Nick Koston" Date: Sun, 8 Mar 2026 17:42:17 -1000 Subject: [PATCH 06/15] Remove len==0 guard from parse(), add debug assert All callers guarantee len > 0 (decode loop checks ptr < end, header parse checks minimum bytes). Replace runtime check with ESPHOME_DEBUG_API assert. This removes the len check from the inline entirely, saving one branch per call site. Co-Authored-By: Claude Opus 4.6 --- esphome/components/api/proto.cpp | 2 -- esphome/components/api/proto.h | 10 ++++++---- 2 files changed, 6 insertions(+), 6 deletions(-) diff --git a/esphome/components/api/proto.cpp b/esphome/components/api/proto.cpp index 4cbc8f46c2..7e01185849 100644 --- a/esphome/components/api/proto.cpp +++ b/esphome/components/api/proto.cpp @@ -21,8 +21,6 @@ void ProtoWriteBuffer::encode_varint_raw_slow_(uint32_t value) { } ProtoVarIntResult ProtoVarInt::parse_slow(const uint8_t *buffer, uint32_t len) { - if (len == 0) - return {0, 0}; // Multi-byte varint: first byte already checked to have high bit set uint32_t result32 = buffer[0] & 0x7F; #ifdef USE_API_VARINT64 diff --git a/esphome/components/api/proto.h b/esphome/components/api/proto.h index 55054ed157..ebb0ecdd79 100644 --- a/esphome/components/api/proto.h +++ b/esphome/components/api/proto.h @@ -130,13 +130,15 @@ class ProtoVarInt { ProtoVarInt() : value_(0) {} explicit ProtoVarInt(uint64_t value) : value_(value) {} - /// Parse a varint from buffer. Returns result with consumed=0 on failure. + /// Parse a varint from buffer. Caller must ensure len >= 1. + /// Returns result with consumed=0 on failure (truncated multi-byte varint). static inline ProtoVarIntResult ESPHOME_ALWAYS_INLINE parse(const uint8_t *buffer, uint32_t len) { +#ifdef ESPHOME_DEBUG_API + assert(len > 0); // All callers guarantee len > 0 +#endif // Fast path: single-byte varints (0-127) are the most common case // (booleans, small enums, field tags, small message sizes/types). - // len==0 check is folded into the condition to minimize inline size; - // parse_slow() handles len==0. - if (len != 0 && (buffer[0] & 0x80) == 0) [[likely]] + if ((buffer[0] & 0x80) == 0) [[likely]] return {buffer[0], 1}; return parse_slow(buffer, len); } From f3ca86b67017991a13a1cb27b242b373e64ed29e Mon Sep 17 00:00:00 2001 From: Clyde Stubbs <2366188+clydebarrow@users.noreply.github.com> Date: Mon, 9 Mar 2026 14:48:03 +1100 Subject: [PATCH 07/15] [ci-custom] Directions on constant hoisting (#14637) --- script/ci-custom.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/script/ci-custom.py b/script/ci-custom.py index 8e1652b505..06fcdadb8c 100755 --- a/script/ci-custom.py +++ b/script/ci-custom.py @@ -519,7 +519,7 @@ def lint_constants_usage(): continue errs.append( f"Constant {highlight(constant)} is defined in {len(uses)} files. Please move all definitions of the " - f"constant to const.py (Uses: {', '.join(str(u) for u in uses)}) in a separate PR. " + f"constant to esphome/components/const/__init__.py (Uses: {', '.join(str(u) for u in uses)}) in a separate PR. " "See https://developers.esphome.io/contributing/code/#python" ) return errs From 0db9137d9101a04c4b2a8836e13308de60280c35 Mon Sep 17 00:00:00 2001 From: Jonathan Swoboda <154711427+swoboda1337@users.noreply.github.com> Date: Mon, 9 Mar 2026 00:10:48 -0400 Subject: [PATCH 08/15] [multiple] Add division by zero guards (#14634) Co-authored-by: Claude Opus 4.6 Co-authored-by: J. Nick Koston --- esphome/components/bl0942/bl0942.cpp | 2 +- esphome/components/combination/combination.cpp | 11 ++++++++++- esphome/components/graph/graph.cpp | 2 +- esphome/components/mics_4514/mics_4514.cpp | 6 ++++++ esphome/components/tsl2561/tsl2561.cpp | 4 ++++ esphome/components/ufire_ec/ufire_ec.cpp | 14 +++++++++++--- esphome/components/ufire_ec/ufire_ec.h | 2 +- esphome/components/xxtea/xxtea.cpp | 4 ++++ 8 files changed, 38 insertions(+), 7 deletions(-) diff --git a/esphome/components/bl0942/bl0942.cpp b/esphome/components/bl0942/bl0942.cpp index 16ad33141d..7d38597423 100644 --- a/esphome/components/bl0942/bl0942.cpp +++ b/esphome/components/bl0942/bl0942.cpp @@ -173,7 +173,7 @@ void BL0942::received_package_(DataPacket *data) { float i_rms = (uint24_t) data->i_rms / current_reference_; float watt = (int24_t) data->watt / power_reference_; float total_energy_consumption = cf_cnt / energy_reference_; - float frequency = 1000000.0f / data->frequency; + float frequency = data->frequency != 0 ? 1000000.0f / data->frequency : NAN; if (voltage_sensor_ != nullptr) { voltage_sensor_->publish_state(v_rms); diff --git a/esphome/components/combination/combination.cpp b/esphome/components/combination/combination.cpp index ece7cca482..2f0bd26a02 100644 --- a/esphome/components/combination/combination.cpp +++ b/esphome/components/combination/combination.cpp @@ -163,7 +163,7 @@ void MeanCombinationComponent::handle_new_value(float value) { return; float sum = 0.0; - size_t count = 0.0; + size_t count = 0; for (const auto &sensor : this->sensors_) { if (std::isfinite(sensor->state)) { @@ -172,6 +172,10 @@ void MeanCombinationComponent::handle_new_value(float value) { } } + if (count == 0) { + this->publish_state(NAN); + return; + } float mean = sum / count; this->publish_state(mean); @@ -238,6 +242,11 @@ void RangeCombinationComponent::handle_new_value(float value) { } } + if (sensor_states.empty()) { + this->publish_state(NAN); + return; + } + sort(sensor_states.begin(), sensor_states.end()); float range = sensor_states.back() - sensor_states.front(); diff --git a/esphome/components/graph/graph.cpp b/esphome/components/graph/graph.cpp index c43cd07fe0..801c97e3f5 100644 --- a/esphome/components/graph/graph.cpp +++ b/esphome/components/graph/graph.cpp @@ -171,7 +171,7 @@ void Graph::draw(Display *buff, uint16_t x_offset, uint16_t y_offset, Color colo bool prev_b = false; int16_t prev_y = 0; for (uint32_t i = 0; i < this->width_; i++) { - float v = (trace->get_tracedata()->get_value(i) - ymin) / yrange; + float v = yrange != 0 ? (trace->get_tracedata()->get_value(i) - ymin) / yrange : NAN; if (!std::isnan(v) && (thick > 0)) { int16_t x = this->width_ - 1 - i + x_offset; uint8_t bit = 1 << ((i % (thick * LineType::PATTERN_LENGTH)) / thick); diff --git a/esphome/components/mics_4514/mics_4514.cpp b/esphome/components/mics_4514/mics_4514.cpp index 60413b32d7..ce63a7d062 100644 --- a/esphome/components/mics_4514/mics_4514.cpp +++ b/esphome/components/mics_4514/mics_4514.cpp @@ -59,6 +59,12 @@ void MICS4514Component::update() { return; } + if (this->red_calibration_ == 0 || this->ox_calibration_ == 0) { + ESP_LOGW(TAG, "Calibration values are zero, retrying"); + this->status_set_warning(); + this->initial_ = true; + return; + } float red_f = (float) (power - red) / this->red_calibration_; float ox_f = (float) (power - ox) / this->ox_calibration_; diff --git a/esphome/components/tsl2561/tsl2561.cpp b/esphome/components/tsl2561/tsl2561.cpp index cb4c38a83c..bccff1fb26 100644 --- a/esphome/components/tsl2561/tsl2561.cpp +++ b/esphome/components/tsl2561/tsl2561.cpp @@ -70,6 +70,10 @@ float TSL2561Sensor::calculate_lx_(uint16_t ch0, uint16_t ch1) { return NAN; } + if (ch0 == 0) { + ESP_LOGVV(TAG, "No light detected"); + return 0.0f; + } float d0 = ch0, d1 = ch1; float ratio = d1 / d0; diff --git a/esphome/components/ufire_ec/ufire_ec.cpp b/esphome/components/ufire_ec/ufire_ec.cpp index a1c3568a1a..40e3be2757 100644 --- a/esphome/components/ufire_ec/ufire_ec.cpp +++ b/esphome/components/ufire_ec/ufire_ec.cpp @@ -1,5 +1,6 @@ #include "esphome/core/log.h" #include "ufire_ec.h" +#include namespace esphome { namespace ufire_ec { @@ -60,9 +61,15 @@ float UFireECComponent::measure_temperature_() { return this->read_data_(REGISTE float UFireECComponent::measure_ms_() { return this->read_data_(REGISTER_MS); } -void UFireECComponent::set_solution_(float solution, float temperature) { - solution /= (1 - (this->temperature_coefficient_ * (temperature - 25))); +bool UFireECComponent::set_solution_(float solution, float temperature) { + float denom = 1 - (this->temperature_coefficient_ * (temperature - 25)); + if (std::abs(denom) < 1e-6f) { + ESP_LOGE(TAG, "Temperature compensation denominator is zero"); + return false; + } + solution /= denom; this->write_data_(REGISTER_SOLUTION, solution); + return true; } void UFireECComponent::set_compensation_(float temperature) { this->write_data_(REGISTER_COMPENSATION, temperature); } @@ -72,7 +79,8 @@ void UFireECComponent::set_coefficient_(float coefficient) { this->write_data_(R void UFireECComponent::set_temperature_(float temperature) { this->write_data_(REGISTER_TEMP, temperature); } void UFireECComponent::calibrate_probe(float solution, float temperature) { - this->set_solution_(solution, temperature); + if (!this->set_solution_(solution, temperature)) + return; this->write_byte(REGISTER_TASK, COMMAND_CALIBRATE_PROBE); } diff --git a/esphome/components/ufire_ec/ufire_ec.h b/esphome/components/ufire_ec/ufire_ec.h index bfbed1b43e..8a648b5038 100644 --- a/esphome/components/ufire_ec/ufire_ec.h +++ b/esphome/components/ufire_ec/ufire_ec.h @@ -44,7 +44,7 @@ class UFireECComponent : public PollingComponent, public i2c::I2CDevice { protected: float measure_temperature_(); float measure_ms_(); - void set_solution_(float solution, float temperature); + bool set_solution_(float solution, float temperature); void set_compensation_(float temperature); void set_coefficient_(float coefficient); void set_temperature_(float temperature); diff --git a/esphome/components/xxtea/xxtea.cpp b/esphome/components/xxtea/xxtea.cpp index aae663ee01..ba17530b24 100644 --- a/esphome/components/xxtea/xxtea.cpp +++ b/esphome/components/xxtea/xxtea.cpp @@ -7,6 +7,8 @@ static const uint32_t DELTA = 0x9e3779b9; #define MX ((((z >> 5) ^ (y << 2)) + ((y >> 3) ^ (z << 4))) ^ ((sum ^ y) + (k[(p ^ e) & 7] ^ z))) void encrypt(uint32_t *v, size_t n, const uint32_t *k) { + if (n == 0) + return; uint32_t z, y, sum, e; size_t p; size_t q = 6 + 52 / n; @@ -25,6 +27,8 @@ void encrypt(uint32_t *v, size_t n, const uint32_t *k) { } void decrypt(uint32_t *v, size_t n, const uint32_t *k) { + if (n == 0) + return; uint32_t z, y, sum, e; size_t p; size_t q = 6 + 52 / n; From f4724d77975fa4a141c1613084158efe4286fbc7 Mon Sep 17 00:00:00 2001 From: "J. Nick Koston" Date: Sun, 8 Mar 2026 18:18:19 -1000 Subject: [PATCH 09/15] Split parse() into parse() and parse_non_empty() parse_non_empty() has no len==0 check (with debug assert) for callers that guarantee len >= 1 (e.g. after while (ptr < end)). parse() adds the len==0 guard and delegates to parse_non_empty() for callers where the buffer may be empty (e.g. value parse after tag advance in decode(), frame helper header parsing). Co-Authored-By: Claude Opus 4.6 --- .../components/api/api_frame_helper_plaintext.cpp | 3 ++- esphome/components/api/proto.cpp | 8 ++++---- esphome/components/api/proto.h | 12 ++++++++++-- 3 files changed, 16 insertions(+), 7 deletions(-) diff --git a/esphome/components/api/api_frame_helper_plaintext.cpp b/esphome/components/api/api_frame_helper_plaintext.cpp index 2fdcd87da5..2fd9196579 100644 --- a/esphome/components/api/api_frame_helper_plaintext.cpp +++ b/esphome/components/api/api_frame_helper_plaintext.cpp @@ -129,7 +129,8 @@ APIError APIPlaintextFrameHelper::try_read_frame_() { // Skip indicator byte at position 0 uint8_t varint_pos = 1; - auto msg_size_varint = ProtoVarInt::parse(&rx_header_buf_[varint_pos], rx_header_buf_pos_ - varint_pos); + // rx_header_buf_pos_ >= 3 and varint_pos == 1, so len >= 2 + auto msg_size_varint = ProtoVarInt::parse_non_empty(&rx_header_buf_[varint_pos], rx_header_buf_pos_ - varint_pos); if (!msg_size_varint.has_value()) { // not enough data there yet continue; diff --git a/esphome/components/api/proto.cpp b/esphome/components/api/proto.cpp index 7e01185849..5dbeae7758 100644 --- a/esphome/components/api/proto.cpp +++ b/esphome/components/api/proto.cpp @@ -63,8 +63,8 @@ uint32_t ProtoDecodableMessage::count_repeated_field(const uint8_t *buffer, size const uint8_t *end = buffer + length; while (ptr < end) { - // Parse field header (tag) - auto res = ProtoVarInt::parse(ptr, end - ptr); + // Parse field header (tag) - ptr < end guarantees len >= 1 + auto res = ProtoVarInt::parse_non_empty(ptr, end - ptr); if (!res.has_value()) { break; // Invalid data, stop counting } @@ -208,8 +208,8 @@ void ProtoDecodableMessage::decode(const uint8_t *buffer, size_t length) { const uint8_t *end = buffer + length; while (ptr < end) { - // Parse field header - auto res = ProtoVarInt::parse(ptr, end - ptr); + // Parse field header - ptr < end guarantees len >= 1 + auto res = ProtoVarInt::parse_non_empty(ptr, end - ptr); if (!res.has_value()) { ESP_LOGV(TAG, "Invalid field start at offset %ld", (long) (ptr - buffer)); return; diff --git a/esphome/components/api/proto.h b/esphome/components/api/proto.h index ebb0ecdd79..86746c949f 100644 --- a/esphome/components/api/proto.h +++ b/esphome/components/api/proto.h @@ -132,9 +132,9 @@ class ProtoVarInt { /// Parse a varint from buffer. Caller must ensure len >= 1. /// Returns result with consumed=0 on failure (truncated multi-byte varint). - static inline ProtoVarIntResult ESPHOME_ALWAYS_INLINE parse(const uint8_t *buffer, uint32_t len) { + static inline ProtoVarIntResult ESPHOME_ALWAYS_INLINE parse_non_empty(const uint8_t *buffer, uint32_t len) { #ifdef ESPHOME_DEBUG_API - assert(len > 0); // All callers guarantee len > 0 + assert(len > 0); #endif // Fast path: single-byte varints (0-127) are the most common case // (booleans, small enums, field tags, small message sizes/types). @@ -143,6 +143,14 @@ class ProtoVarInt { return parse_slow(buffer, len); } + /// Parse a varint from buffer (safe for empty buffers). + /// Returns result with consumed=0 on failure (empty buffer or truncated varint). + static inline ProtoVarIntResult ESPHOME_ALWAYS_INLINE parse(const uint8_t *buffer, uint32_t len) { + if (len == 0) + return {0, PROTO_VARINT_PARSE_FAILED}; + return parse_non_empty(buffer, len); + } + protected: // Slow path for multi-byte varints (>= 128), outlined to keep fast path small static ProtoVarIntResult parse_slow(const uint8_t *buffer, uint32_t len) __attribute__((noinline)); From fcd72336f03bc7733371717f6d1ee857410160e2 Mon Sep 17 00:00:00 2001 From: "J. Nick Koston" Date: Sun, 8 Mar 2026 18:39:59 -1000 Subject: [PATCH 10/15] [api] Change decode_varint parameter from ProtoVarIntResult to raw value type Pass uint32_t (or uint64_t when USE_API_VARINT64 is defined) directly to decode_varint() instead of the ProtoVarIntResult struct. This eliminates accessor method overhead in each of the 51 overrides, replacing value.as_uint32() with direct value usage, value.as_bool() with value != 0, etc. No vtable growth - single virtual method with conditionally-typed parameter. Co-Authored-By: Claude Opus 4.6 --- esphome/components/api/api_pb2.cpp | 634 ++++++++++++++++++---------- esphome/components/api/api_pb2.h | 306 +++++++++++--- esphome/components/api/proto.cpp | 6 +- esphome/components/api/proto.h | 6 +- script/api_protobuf/api_protobuf.py | 44 +- 5 files changed, 715 insertions(+), 281 deletions(-) diff --git a/esphome/components/api/api_pb2.cpp b/esphome/components/api/api_pb2.cpp index 7d32a5123e..2458c4b2a5 100644 --- a/esphome/components/api/api_pb2.cpp +++ b/esphome/components/api/api_pb2.cpp @@ -7,13 +7,17 @@ namespace esphome::api { -bool HelloRequest::decode_varint(uint32_t field_id, ProtoVarIntResult value) { +#ifdef USE_API_VARINT64 +bool HelloRequest::decode_varint(uint32_t field_id, uint64_t value) { +#else +bool HelloRequest::decode_varint(uint32_t field_id, uint32_t value) { +#endif switch (field_id) { case 2: - this->api_version_major = value.as_uint32(); + this->api_version_major = value; break; case 3: - this->api_version_minor = value.as_uint32(); + this->api_version_minor = value; break; default: return false; @@ -316,20 +320,24 @@ uint32_t CoverStateResponse::calculate_size() const { #endif return size; } -bool CoverCommandRequest::decode_varint(uint32_t field_id, ProtoVarIntResult value) { +#ifdef USE_API_VARINT64 +bool CoverCommandRequest::decode_varint(uint32_t field_id, uint64_t value) { +#else +bool CoverCommandRequest::decode_varint(uint32_t field_id, uint32_t value) { +#endif switch (field_id) { case 4: - this->has_position = value.as_bool(); + this->has_position = value != 0; break; case 6: - this->has_tilt = value.as_bool(); + this->has_tilt = value != 0; break; case 8: - this->stop = value.as_bool(); + this->stop = value != 0; break; #ifdef USE_DEVICES case 9: - this->device_id = value.as_uint32(); + this->device_id = value; break; #endif default: @@ -423,38 +431,42 @@ uint32_t FanStateResponse::calculate_size() const { #endif return size; } -bool FanCommandRequest::decode_varint(uint32_t field_id, ProtoVarIntResult value) { +#ifdef USE_API_VARINT64 +bool FanCommandRequest::decode_varint(uint32_t field_id, uint64_t value) { +#else +bool FanCommandRequest::decode_varint(uint32_t field_id, uint32_t value) { +#endif switch (field_id) { case 2: - this->has_state = value.as_bool(); + this->has_state = value != 0; break; case 3: - this->state = value.as_bool(); + this->state = value != 0; break; case 6: - this->has_oscillating = value.as_bool(); + this->has_oscillating = value != 0; break; case 7: - this->oscillating = value.as_bool(); + this->oscillating = value != 0; break; case 8: - this->has_direction = value.as_bool(); + this->has_direction = value != 0; break; case 9: - this->direction = static_cast(value.as_uint32()); + this->direction = static_cast(value); break; case 10: - this->has_speed_level = value.as_bool(); + this->has_speed_level = value != 0; break; case 11: - this->speed_level = value.as_int32(); + this->speed_level = static_cast(value); break; case 12: - this->has_preset_mode = value.as_bool(); + this->has_preset_mode = value != 0; break; #ifdef USE_DEVICES case 14: - this->device_id = value.as_uint32(); + this->device_id = value; break; #endif default: @@ -571,59 +583,63 @@ uint32_t LightStateResponse::calculate_size() const { #endif return size; } -bool LightCommandRequest::decode_varint(uint32_t field_id, ProtoVarIntResult value) { +#ifdef USE_API_VARINT64 +bool LightCommandRequest::decode_varint(uint32_t field_id, uint64_t value) { +#else +bool LightCommandRequest::decode_varint(uint32_t field_id, uint32_t value) { +#endif switch (field_id) { case 2: - this->has_state = value.as_bool(); + this->has_state = value != 0; break; case 3: - this->state = value.as_bool(); + this->state = value != 0; break; case 4: - this->has_brightness = value.as_bool(); + this->has_brightness = value != 0; break; case 22: - this->has_color_mode = value.as_bool(); + this->has_color_mode = value != 0; break; case 23: - this->color_mode = static_cast(value.as_uint32()); + this->color_mode = static_cast(value); break; case 20: - this->has_color_brightness = value.as_bool(); + this->has_color_brightness = value != 0; break; case 6: - this->has_rgb = value.as_bool(); + this->has_rgb = value != 0; break; case 10: - this->has_white = value.as_bool(); + this->has_white = value != 0; break; case 12: - this->has_color_temperature = value.as_bool(); + this->has_color_temperature = value != 0; break; case 24: - this->has_cold_white = value.as_bool(); + this->has_cold_white = value != 0; break; case 26: - this->has_warm_white = value.as_bool(); + this->has_warm_white = value != 0; break; case 14: - this->has_transition_length = value.as_bool(); + this->has_transition_length = value != 0; break; case 15: - this->transition_length = value.as_uint32(); + this->transition_length = value; break; case 16: - this->has_flash_length = value.as_bool(); + this->has_flash_length = value != 0; break; case 17: - this->flash_length = value.as_uint32(); + this->flash_length = value; break; case 18: - this->has_effect = value.as_bool(); + this->has_effect = value != 0; break; #ifdef USE_DEVICES case 28: - this->device_id = value.as_uint32(); + this->device_id = value; break; #endif default: @@ -787,14 +803,18 @@ uint32_t SwitchStateResponse::calculate_size() const { #endif return size; } -bool SwitchCommandRequest::decode_varint(uint32_t field_id, ProtoVarIntResult value) { +#ifdef USE_API_VARINT64 +bool SwitchCommandRequest::decode_varint(uint32_t field_id, uint64_t value) { +#else +bool SwitchCommandRequest::decode_varint(uint32_t field_id, uint32_t value) { +#endif switch (field_id) { case 2: - this->state = value.as_bool(); + this->state = value != 0; break; #ifdef USE_DEVICES case 3: - this->device_id = value.as_uint32(); + this->device_id = value; break; #endif default: @@ -863,13 +883,17 @@ uint32_t TextSensorStateResponse::calculate_size() const { return size; } #endif -bool SubscribeLogsRequest::decode_varint(uint32_t field_id, ProtoVarIntResult value) { +#ifdef USE_API_VARINT64 +bool SubscribeLogsRequest::decode_varint(uint32_t field_id, uint64_t value) { +#else +bool SubscribeLogsRequest::decode_varint(uint32_t field_id, uint32_t value) { +#endif switch (field_id) { case 1: - this->level = static_cast(value.as_uint32()); + this->level = static_cast(value); break; case 2: - this->dump_config = value.as_bool(); + this->dump_config = value != 0; break; default: return false; @@ -971,13 +995,17 @@ uint32_t HomeassistantActionRequest::calculate_size() const { } #endif #ifdef USE_API_HOMEASSISTANT_ACTION_RESPONSES -bool HomeassistantActionResponse::decode_varint(uint32_t field_id, ProtoVarIntResult value) { +#ifdef USE_API_VARINT64 +bool HomeassistantActionResponse::decode_varint(uint32_t field_id, uint64_t value) { +#else +bool HomeassistantActionResponse::decode_varint(uint32_t field_id, uint32_t value) { +#endif switch (field_id) { case 1: - this->call_id = value.as_uint32(); + this->call_id = value; break; case 2: - this->success = value.as_bool(); + this->success = value != 0; break; default: return false; @@ -1036,38 +1064,46 @@ bool HomeAssistantStateResponse::decode_length(uint32_t field_id, ProtoLengthDel return true; } #endif -bool DSTRule::decode_varint(uint32_t field_id, ProtoVarIntResult value) { +#ifdef USE_API_VARINT64 +bool DSTRule::decode_varint(uint32_t field_id, uint64_t value) { +#else +bool DSTRule::decode_varint(uint32_t field_id, uint32_t value) { +#endif switch (field_id) { case 1: - this->time_seconds = value.as_sint32(); + this->time_seconds = decode_zigzag32(value); break; case 2: - this->day = value.as_uint32(); + this->day = value; break; case 3: - this->type = static_cast(value.as_uint32()); + this->type = static_cast(value); break; case 4: - this->month = value.as_uint32(); + this->month = value; break; case 5: - this->week = value.as_uint32(); + this->week = value; break; case 6: - this->day_of_week = value.as_uint32(); + this->day_of_week = value; break; default: return false; } return true; } -bool ParsedTimezone::decode_varint(uint32_t field_id, ProtoVarIntResult value) { +#ifdef USE_API_VARINT64 +bool ParsedTimezone::decode_varint(uint32_t field_id, uint64_t value) { +#else +bool ParsedTimezone::decode_varint(uint32_t field_id, uint32_t value) { +#endif switch (field_id) { case 1: - this->std_offset_seconds = value.as_sint32(); + this->std_offset_seconds = decode_zigzag32(value); break; case 2: - this->dst_offset_seconds = value.as_sint32(); + this->dst_offset_seconds = decode_zigzag32(value); break; default: return false; @@ -1142,22 +1178,26 @@ uint32_t ListEntitiesServicesResponse::calculate_size() const { size += ProtoSize::calc_uint32(1, static_cast(this->supports_response)); return size; } -bool ExecuteServiceArgument::decode_varint(uint32_t field_id, ProtoVarIntResult value) { +#ifdef USE_API_VARINT64 +bool ExecuteServiceArgument::decode_varint(uint32_t field_id, uint64_t value) { +#else +bool ExecuteServiceArgument::decode_varint(uint32_t field_id, uint32_t value) { +#endif switch (field_id) { case 1: - this->bool_ = value.as_bool(); + this->bool_ = value != 0; break; case 2: - this->legacy_int = value.as_int32(); + this->legacy_int = static_cast(value); break; case 5: - this->int_ = value.as_sint32(); + this->int_ = decode_zigzag32(value); break; case 6: - this->bool_array.push_back(value.as_bool()); + this->bool_array.push_back(value != 0); break; case 7: - this->int_array.push_back(value.as_sint32()); + this->int_array.push_back(decode_zigzag32(value)); break; default: return false; @@ -1202,16 +1242,20 @@ void ExecuteServiceArgument::decode(const uint8_t *buffer, size_t length) { this->string_array.init(count_string_array); ProtoDecodableMessage::decode(buffer, length); } -bool ExecuteServiceRequest::decode_varint(uint32_t field_id, ProtoVarIntResult value) { +#ifdef USE_API_VARINT64 +bool ExecuteServiceRequest::decode_varint(uint32_t field_id, uint64_t value) { +#else +bool ExecuteServiceRequest::decode_varint(uint32_t field_id, uint32_t value) { +#endif switch (field_id) { #ifdef USE_API_USER_DEFINED_ACTION_RESPONSES case 3: - this->call_id = value.as_uint32(); + this->call_id = value; break; #endif #ifdef USE_API_USER_DEFINED_ACTION_RESPONSES case 4: - this->return_response = value.as_bool(); + this->return_response = value != 0; break; #endif default: @@ -1313,13 +1357,17 @@ uint32_t CameraImageResponse::calculate_size() const { #endif return size; } -bool CameraImageRequest::decode_varint(uint32_t field_id, ProtoVarIntResult value) { +#ifdef USE_API_VARINT64 +bool CameraImageRequest::decode_varint(uint32_t field_id, uint64_t value) { +#else +bool CameraImageRequest::decode_varint(uint32_t field_id, uint32_t value) { +#endif switch (field_id) { case 1: - this->single = value.as_bool(); + this->single = value != 0; break; case 2: - this->stream = value.as_bool(); + this->stream = value != 0; break; default: return false; @@ -1468,53 +1516,57 @@ uint32_t ClimateStateResponse::calculate_size() const { #endif return size; } -bool ClimateCommandRequest::decode_varint(uint32_t field_id, ProtoVarIntResult value) { +#ifdef USE_API_VARINT64 +bool ClimateCommandRequest::decode_varint(uint32_t field_id, uint64_t value) { +#else +bool ClimateCommandRequest::decode_varint(uint32_t field_id, uint32_t value) { +#endif switch (field_id) { case 2: - this->has_mode = value.as_bool(); + this->has_mode = value != 0; break; case 3: - this->mode = static_cast(value.as_uint32()); + this->mode = static_cast(value); break; case 4: - this->has_target_temperature = value.as_bool(); + this->has_target_temperature = value != 0; break; case 6: - this->has_target_temperature_low = value.as_bool(); + this->has_target_temperature_low = value != 0; break; case 8: - this->has_target_temperature_high = value.as_bool(); + this->has_target_temperature_high = value != 0; break; case 12: - this->has_fan_mode = value.as_bool(); + this->has_fan_mode = value != 0; break; case 13: - this->fan_mode = static_cast(value.as_uint32()); + this->fan_mode = static_cast(value); break; case 14: - this->has_swing_mode = value.as_bool(); + this->has_swing_mode = value != 0; break; case 15: - this->swing_mode = static_cast(value.as_uint32()); + this->swing_mode = static_cast(value); break; case 16: - this->has_custom_fan_mode = value.as_bool(); + this->has_custom_fan_mode = value != 0; break; case 18: - this->has_preset = value.as_bool(); + this->has_preset = value != 0; break; case 19: - this->preset = static_cast(value.as_uint32()); + this->preset = static_cast(value); break; case 20: - this->has_custom_preset = value.as_bool(); + this->has_custom_preset = value != 0; break; case 22: - this->has_target_humidity = value.as_bool(); + this->has_target_humidity = value != 0; break; #ifdef USE_DEVICES case 24: - this->device_id = value.as_uint32(); + this->device_id = value; break; #endif default: @@ -1631,21 +1683,25 @@ uint32_t WaterHeaterStateResponse::calculate_size() const { size += ProtoSize::calc_float(1, this->target_temperature_high); return size; } -bool WaterHeaterCommandRequest::decode_varint(uint32_t field_id, ProtoVarIntResult value) { +#ifdef USE_API_VARINT64 +bool WaterHeaterCommandRequest::decode_varint(uint32_t field_id, uint64_t value) { +#else +bool WaterHeaterCommandRequest::decode_varint(uint32_t field_id, uint32_t value) { +#endif switch (field_id) { case 2: - this->has_fields = value.as_uint32(); + this->has_fields = value; break; case 3: - this->mode = static_cast(value.as_uint32()); + this->mode = static_cast(value); break; #ifdef USE_DEVICES case 5: - this->device_id = value.as_uint32(); + this->device_id = value; break; #endif case 6: - this->state = value.as_uint32(); + this->state = value; break; default: return false; @@ -1731,11 +1787,15 @@ uint32_t NumberStateResponse::calculate_size() const { #endif return size; } -bool NumberCommandRequest::decode_varint(uint32_t field_id, ProtoVarIntResult value) { +#ifdef USE_API_VARINT64 +bool NumberCommandRequest::decode_varint(uint32_t field_id, uint64_t value) { +#else +bool NumberCommandRequest::decode_varint(uint32_t field_id, uint32_t value) { +#endif switch (field_id) { #ifdef USE_DEVICES case 3: - this->device_id = value.as_uint32(); + this->device_id = value; break; #endif default: @@ -1812,11 +1872,15 @@ uint32_t SelectStateResponse::calculate_size() const { #endif return size; } -bool SelectCommandRequest::decode_varint(uint32_t field_id, ProtoVarIntResult value) { +#ifdef USE_API_VARINT64 +bool SelectCommandRequest::decode_varint(uint32_t field_id, uint64_t value) { +#else +bool SelectCommandRequest::decode_varint(uint32_t field_id, uint32_t value) { +#endif switch (field_id) { #ifdef USE_DEVICES case 3: - this->device_id = value.as_uint32(); + this->device_id = value; break; #endif default: @@ -1903,29 +1967,33 @@ uint32_t SirenStateResponse::calculate_size() const { #endif return size; } -bool SirenCommandRequest::decode_varint(uint32_t field_id, ProtoVarIntResult value) { +#ifdef USE_API_VARINT64 +bool SirenCommandRequest::decode_varint(uint32_t field_id, uint64_t value) { +#else +bool SirenCommandRequest::decode_varint(uint32_t field_id, uint32_t value) { +#endif switch (field_id) { case 2: - this->has_state = value.as_bool(); + this->has_state = value != 0; break; case 3: - this->state = value.as_bool(); + this->state = value != 0; break; case 4: - this->has_tone = value.as_bool(); + this->has_tone = value != 0; break; case 6: - this->has_duration = value.as_bool(); + this->has_duration = value != 0; break; case 7: - this->duration = value.as_uint32(); + this->duration = value; break; case 8: - this->has_volume = value.as_bool(); + this->has_volume = value != 0; break; #ifdef USE_DEVICES case 10: - this->device_id = value.as_uint32(); + this->device_id = value; break; #endif default: @@ -2011,17 +2079,21 @@ uint32_t LockStateResponse::calculate_size() const { #endif return size; } -bool LockCommandRequest::decode_varint(uint32_t field_id, ProtoVarIntResult value) { +#ifdef USE_API_VARINT64 +bool LockCommandRequest::decode_varint(uint32_t field_id, uint64_t value) { +#else +bool LockCommandRequest::decode_varint(uint32_t field_id, uint32_t value) { +#endif switch (field_id) { case 2: - this->command = static_cast(value.as_uint32()); + this->command = static_cast(value); break; case 3: - this->has_code = value.as_bool(); + this->has_code = value != 0; break; #ifdef USE_DEVICES case 5: - this->device_id = value.as_uint32(); + this->device_id = value; break; #endif default: @@ -2082,11 +2154,15 @@ uint32_t ListEntitiesButtonResponse::calculate_size() const { #endif return size; } -bool ButtonCommandRequest::decode_varint(uint32_t field_id, ProtoVarIntResult value) { +#ifdef USE_API_VARINT64 +bool ButtonCommandRequest::decode_varint(uint32_t field_id, uint64_t value) { +#else +bool ButtonCommandRequest::decode_varint(uint32_t field_id, uint32_t value) { +#endif switch (field_id) { #ifdef USE_DEVICES case 2: - this->device_id = value.as_uint32(); + this->device_id = value; break; #endif default: @@ -2182,29 +2258,33 @@ uint32_t MediaPlayerStateResponse::calculate_size() const { #endif return size; } -bool MediaPlayerCommandRequest::decode_varint(uint32_t field_id, ProtoVarIntResult value) { +#ifdef USE_API_VARINT64 +bool MediaPlayerCommandRequest::decode_varint(uint32_t field_id, uint64_t value) { +#else +bool MediaPlayerCommandRequest::decode_varint(uint32_t field_id, uint32_t value) { +#endif switch (field_id) { case 2: - this->has_command = value.as_bool(); + this->has_command = value != 0; break; case 3: - this->command = static_cast(value.as_uint32()); + this->command = static_cast(value); break; case 4: - this->has_volume = value.as_bool(); + this->has_volume = value != 0; break; case 6: - this->has_media_url = value.as_bool(); + this->has_media_url = value != 0; break; case 8: - this->has_announcement = value.as_bool(); + this->has_announcement = value != 0; break; case 9: - this->announcement = value.as_bool(); + this->announcement = value != 0; break; #ifdef USE_DEVICES case 10: - this->device_id = value.as_uint32(); + this->device_id = value; break; #endif default: @@ -2238,10 +2318,14 @@ bool MediaPlayerCommandRequest::decode_32bit(uint32_t field_id, Proto32Bit value } #endif #ifdef USE_BLUETOOTH_PROXY -bool SubscribeBluetoothLEAdvertisementsRequest::decode_varint(uint32_t field_id, ProtoVarIntResult value) { +#ifdef USE_API_VARINT64 +bool SubscribeBluetoothLEAdvertisementsRequest::decode_varint(uint32_t field_id, uint64_t value) { +#else +bool SubscribeBluetoothLEAdvertisementsRequest::decode_varint(uint32_t field_id, uint32_t value) { +#endif switch (field_id) { case 1: - this->flags = value.as_uint32(); + this->flags = value; break; default: return false; @@ -2274,19 +2358,23 @@ uint32_t BluetoothLERawAdvertisementsResponse::calculate_size() const { } return size; } -bool BluetoothDeviceRequest::decode_varint(uint32_t field_id, ProtoVarIntResult value) { +#ifdef USE_API_VARINT64 +bool BluetoothDeviceRequest::decode_varint(uint32_t field_id, uint64_t value) { +#else +bool BluetoothDeviceRequest::decode_varint(uint32_t field_id, uint32_t value) { +#endif switch (field_id) { case 1: - this->address = value.as_uint64(); + this->address = value; break; case 2: - this->request_type = static_cast(value.as_uint32()); + this->request_type = static_cast(value); break; case 3: - this->has_address_type = value.as_bool(); + this->has_address_type = value != 0; break; case 4: - this->address_type = value.as_uint32(); + this->address_type = value; break; default: return false; @@ -2307,10 +2395,14 @@ uint32_t BluetoothDeviceConnectionResponse::calculate_size() const { size += ProtoSize::calc_int32(1, this->error); return size; } -bool BluetoothGATTGetServicesRequest::decode_varint(uint32_t field_id, ProtoVarIntResult value) { +#ifdef USE_API_VARINT64 +bool BluetoothGATTGetServicesRequest::decode_varint(uint32_t field_id, uint64_t value) { +#else +bool BluetoothGATTGetServicesRequest::decode_varint(uint32_t field_id, uint32_t value) { +#endif switch (field_id) { case 1: - this->address = value.as_uint64(); + this->address = value; break; default: return false; @@ -2413,13 +2505,17 @@ uint32_t BluetoothGATTGetServicesDoneResponse::calculate_size() const { size += ProtoSize::calc_uint64(1, this->address); return size; } -bool BluetoothGATTReadRequest::decode_varint(uint32_t field_id, ProtoVarIntResult value) { +#ifdef USE_API_VARINT64 +bool BluetoothGATTReadRequest::decode_varint(uint32_t field_id, uint64_t value) { +#else +bool BluetoothGATTReadRequest::decode_varint(uint32_t field_id, uint32_t value) { +#endif switch (field_id) { case 1: - this->address = value.as_uint64(); + this->address = value; break; case 2: - this->handle = value.as_uint32(); + this->handle = value; break; default: return false; @@ -2438,16 +2534,20 @@ uint32_t BluetoothGATTReadResponse::calculate_size() const { size += ProtoSize::calc_length(1, this->data_len_); return size; } -bool BluetoothGATTWriteRequest::decode_varint(uint32_t field_id, ProtoVarIntResult value) { +#ifdef USE_API_VARINT64 +bool BluetoothGATTWriteRequest::decode_varint(uint32_t field_id, uint64_t value) { +#else +bool BluetoothGATTWriteRequest::decode_varint(uint32_t field_id, uint32_t value) { +#endif switch (field_id) { case 1: - this->address = value.as_uint64(); + this->address = value; break; case 2: - this->handle = value.as_uint32(); + this->handle = value; break; case 3: - this->response = value.as_bool(); + this->response = value != 0; break; default: return false; @@ -2466,26 +2566,34 @@ bool BluetoothGATTWriteRequest::decode_length(uint32_t field_id, ProtoLengthDeli } return true; } -bool BluetoothGATTReadDescriptorRequest::decode_varint(uint32_t field_id, ProtoVarIntResult value) { +#ifdef USE_API_VARINT64 +bool BluetoothGATTReadDescriptorRequest::decode_varint(uint32_t field_id, uint64_t value) { +#else +bool BluetoothGATTReadDescriptorRequest::decode_varint(uint32_t field_id, uint32_t value) { +#endif switch (field_id) { case 1: - this->address = value.as_uint64(); + this->address = value; break; case 2: - this->handle = value.as_uint32(); + this->handle = value; break; default: return false; } return true; } -bool BluetoothGATTWriteDescriptorRequest::decode_varint(uint32_t field_id, ProtoVarIntResult value) { +#ifdef USE_API_VARINT64 +bool BluetoothGATTWriteDescriptorRequest::decode_varint(uint32_t field_id, uint64_t value) { +#else +bool BluetoothGATTWriteDescriptorRequest::decode_varint(uint32_t field_id, uint32_t value) { +#endif switch (field_id) { case 1: - this->address = value.as_uint64(); + this->address = value; break; case 2: - this->handle = value.as_uint32(); + this->handle = value; break; default: return false; @@ -2504,16 +2612,20 @@ bool BluetoothGATTWriteDescriptorRequest::decode_length(uint32_t field_id, Proto } return true; } -bool BluetoothGATTNotifyRequest::decode_varint(uint32_t field_id, ProtoVarIntResult value) { +#ifdef USE_API_VARINT64 +bool BluetoothGATTNotifyRequest::decode_varint(uint32_t field_id, uint64_t value) { +#else +bool BluetoothGATTNotifyRequest::decode_varint(uint32_t field_id, uint32_t value) { +#endif switch (field_id) { case 1: - this->address = value.as_uint64(); + this->address = value; break; case 2: - this->handle = value.as_uint32(); + this->handle = value; break; case 3: - this->enable = value.as_bool(); + this->enable = value != 0; break; default: return false; @@ -2632,10 +2744,14 @@ uint32_t BluetoothScannerStateResponse::calculate_size() const { size += ProtoSize::calc_uint32(1, static_cast(this->configured_mode)); return size; } -bool BluetoothScannerSetModeRequest::decode_varint(uint32_t field_id, ProtoVarIntResult value) { +#ifdef USE_API_VARINT64 +bool BluetoothScannerSetModeRequest::decode_varint(uint32_t field_id, uint64_t value) { +#else +bool BluetoothScannerSetModeRequest::decode_varint(uint32_t field_id, uint32_t value) { +#endif switch (field_id) { case 1: - this->mode = static_cast(value.as_uint32()); + this->mode = static_cast(value); break; default: return false; @@ -2644,13 +2760,17 @@ bool BluetoothScannerSetModeRequest::decode_varint(uint32_t field_id, ProtoVarIn } #endif #ifdef USE_VOICE_ASSISTANT -bool SubscribeVoiceAssistantRequest::decode_varint(uint32_t field_id, ProtoVarIntResult value) { +#ifdef USE_API_VARINT64 +bool SubscribeVoiceAssistantRequest::decode_varint(uint32_t field_id, uint64_t value) { +#else +bool SubscribeVoiceAssistantRequest::decode_varint(uint32_t field_id, uint32_t value) { +#endif switch (field_id) { case 1: - this->subscribe = value.as_bool(); + this->subscribe = value != 0; break; case 2: - this->flags = value.as_uint32(); + this->flags = value; break; default: return false; @@ -2685,13 +2805,17 @@ uint32_t VoiceAssistantRequest::calculate_size() const { size += ProtoSize::calc_length(1, this->wake_word_phrase.size()); return size; } -bool VoiceAssistantResponse::decode_varint(uint32_t field_id, ProtoVarIntResult value) { +#ifdef USE_API_VARINT64 +bool VoiceAssistantResponse::decode_varint(uint32_t field_id, uint64_t value) { +#else +bool VoiceAssistantResponse::decode_varint(uint32_t field_id, uint32_t value) { +#endif switch (field_id) { case 1: - this->port = value.as_uint32(); + this->port = value; break; case 2: - this->error = value.as_bool(); + this->error = value != 0; break; default: return false; @@ -2713,10 +2837,14 @@ bool VoiceAssistantEventData::decode_length(uint32_t field_id, ProtoLengthDelimi } return true; } -bool VoiceAssistantEventResponse::decode_varint(uint32_t field_id, ProtoVarIntResult value) { +#ifdef USE_API_VARINT64 +bool VoiceAssistantEventResponse::decode_varint(uint32_t field_id, uint64_t value) { +#else +bool VoiceAssistantEventResponse::decode_varint(uint32_t field_id, uint32_t value) { +#endif switch (field_id) { case 1: - this->event_type = static_cast(value.as_uint32()); + this->event_type = static_cast(value); break; default: return false; @@ -2734,10 +2862,14 @@ bool VoiceAssistantEventResponse::decode_length(uint32_t field_id, ProtoLengthDe } return true; } -bool VoiceAssistantAudio::decode_varint(uint32_t field_id, ProtoVarIntResult value) { +#ifdef USE_API_VARINT64 +bool VoiceAssistantAudio::decode_varint(uint32_t field_id, uint64_t value) { +#else +bool VoiceAssistantAudio::decode_varint(uint32_t field_id, uint32_t value) { +#endif switch (field_id) { case 2: - this->end = value.as_bool(); + this->end = value != 0; break; default: return false; @@ -2766,19 +2898,23 @@ uint32_t VoiceAssistantAudio::calculate_size() const { size += ProtoSize::calc_bool(1, this->end); return size; } -bool VoiceAssistantTimerEventResponse::decode_varint(uint32_t field_id, ProtoVarIntResult value) { +#ifdef USE_API_VARINT64 +bool VoiceAssistantTimerEventResponse::decode_varint(uint32_t field_id, uint64_t value) { +#else +bool VoiceAssistantTimerEventResponse::decode_varint(uint32_t field_id, uint32_t value) { +#endif switch (field_id) { case 1: - this->event_type = static_cast(value.as_uint32()); + this->event_type = static_cast(value); break; case 4: - this->total_seconds = value.as_uint32(); + this->total_seconds = value; break; case 5: - this->seconds_left = value.as_uint32(); + this->seconds_left = value; break; case 6: - this->is_active = value.as_bool(); + this->is_active = value != 0; break; default: return false; @@ -2800,10 +2936,14 @@ bool VoiceAssistantTimerEventResponse::decode_length(uint32_t field_id, ProtoLen } return true; } -bool VoiceAssistantAnnounceRequest::decode_varint(uint32_t field_id, ProtoVarIntResult value) { +#ifdef USE_API_VARINT64 +bool VoiceAssistantAnnounceRequest::decode_varint(uint32_t field_id, uint64_t value) { +#else +bool VoiceAssistantAnnounceRequest::decode_varint(uint32_t field_id, uint32_t value) { +#endif switch (field_id) { case 4: - this->start_conversation = value.as_bool(); + this->start_conversation = value != 0; break; default: return false; @@ -2853,10 +2993,14 @@ uint32_t VoiceAssistantWakeWord::calculate_size() const { } return size; } -bool VoiceAssistantExternalWakeWord::decode_varint(uint32_t field_id, ProtoVarIntResult value) { +#ifdef USE_API_VARINT64 +bool VoiceAssistantExternalWakeWord::decode_varint(uint32_t field_id, uint64_t value) { +#else +bool VoiceAssistantExternalWakeWord::decode_varint(uint32_t field_id, uint32_t value) { +#endif switch (field_id) { case 5: - this->model_size = value.as_uint32(); + this->model_size = value; break; default: return false; @@ -2990,14 +3134,18 @@ uint32_t AlarmControlPanelStateResponse::calculate_size() const { #endif return size; } -bool AlarmControlPanelCommandRequest::decode_varint(uint32_t field_id, ProtoVarIntResult value) { +#ifdef USE_API_VARINT64 +bool AlarmControlPanelCommandRequest::decode_varint(uint32_t field_id, uint64_t value) { +#else +bool AlarmControlPanelCommandRequest::decode_varint(uint32_t field_id, uint32_t value) { +#endif switch (field_id) { case 2: - this->command = static_cast(value.as_uint32()); + this->command = static_cast(value); break; #ifdef USE_DEVICES case 4: - this->device_id = value.as_uint32(); + this->device_id = value; break; #endif default: @@ -3082,11 +3230,15 @@ uint32_t TextStateResponse::calculate_size() const { #endif return size; } -bool TextCommandRequest::decode_varint(uint32_t field_id, ProtoVarIntResult value) { +#ifdef USE_API_VARINT64 +bool TextCommandRequest::decode_varint(uint32_t field_id, uint64_t value) { +#else +bool TextCommandRequest::decode_varint(uint32_t field_id, uint32_t value) { +#endif switch (field_id) { #ifdef USE_DEVICES case 3: - this->device_id = value.as_uint32(); + this->device_id = value; break; #endif default: @@ -3167,20 +3319,24 @@ uint32_t DateStateResponse::calculate_size() const { #endif return size; } -bool DateCommandRequest::decode_varint(uint32_t field_id, ProtoVarIntResult value) { +#ifdef USE_API_VARINT64 +bool DateCommandRequest::decode_varint(uint32_t field_id, uint64_t value) { +#else +bool DateCommandRequest::decode_varint(uint32_t field_id, uint32_t value) { +#endif switch (field_id) { case 2: - this->year = value.as_uint32(); + this->year = value; break; case 3: - this->month = value.as_uint32(); + this->month = value; break; case 4: - this->day = value.as_uint32(); + this->day = value; break; #ifdef USE_DEVICES case 5: - this->device_id = value.as_uint32(); + this->device_id = value; break; #endif default: @@ -3250,20 +3406,24 @@ uint32_t TimeStateResponse::calculate_size() const { #endif return size; } -bool TimeCommandRequest::decode_varint(uint32_t field_id, ProtoVarIntResult value) { +#ifdef USE_API_VARINT64 +bool TimeCommandRequest::decode_varint(uint32_t field_id, uint64_t value) { +#else +bool TimeCommandRequest::decode_varint(uint32_t field_id, uint32_t value) { +#endif switch (field_id) { case 2: - this->hour = value.as_uint32(); + this->hour = value; break; case 3: - this->minute = value.as_uint32(); + this->minute = value; break; case 4: - this->second = value.as_uint32(); + this->second = value; break; #ifdef USE_DEVICES case 5: - this->device_id = value.as_uint32(); + this->device_id = value; break; #endif default: @@ -3393,17 +3553,21 @@ uint32_t ValveStateResponse::calculate_size() const { #endif return size; } -bool ValveCommandRequest::decode_varint(uint32_t field_id, ProtoVarIntResult value) { +#ifdef USE_API_VARINT64 +bool ValveCommandRequest::decode_varint(uint32_t field_id, uint64_t value) { +#else +bool ValveCommandRequest::decode_varint(uint32_t field_id, uint32_t value) { +#endif switch (field_id) { case 2: - this->has_position = value.as_bool(); + this->has_position = value != 0; break; case 4: - this->stop = value.as_bool(); + this->stop = value != 0; break; #ifdef USE_DEVICES case 5: - this->device_id = value.as_uint32(); + this->device_id = value; break; #endif default: @@ -3472,11 +3636,15 @@ uint32_t DateTimeStateResponse::calculate_size() const { #endif return size; } -bool DateTimeCommandRequest::decode_varint(uint32_t field_id, ProtoVarIntResult value) { +#ifdef USE_API_VARINT64 +bool DateTimeCommandRequest::decode_varint(uint32_t field_id, uint64_t value) { +#else +bool DateTimeCommandRequest::decode_varint(uint32_t field_id, uint32_t value) { +#endif switch (field_id) { #ifdef USE_DEVICES case 3: - this->device_id = value.as_uint32(); + this->device_id = value; break; #endif default: @@ -3561,14 +3729,18 @@ uint32_t UpdateStateResponse::calculate_size() const { #endif return size; } -bool UpdateCommandRequest::decode_varint(uint32_t field_id, ProtoVarIntResult value) { +#ifdef USE_API_VARINT64 +bool UpdateCommandRequest::decode_varint(uint32_t field_id, uint64_t value) { +#else +bool UpdateCommandRequest::decode_varint(uint32_t field_id, uint32_t value) { +#endif switch (field_id) { case 2: - this->command = static_cast(value.as_uint32()); + this->command = static_cast(value); break; #ifdef USE_DEVICES case 3: - this->device_id = value.as_uint32(); + this->device_id = value; break; #endif default: @@ -3606,10 +3778,14 @@ uint32_t ZWaveProxyFrame::calculate_size() const { size += ProtoSize::calc_length(1, this->data_len); return size; } -bool ZWaveProxyRequest::decode_varint(uint32_t field_id, ProtoVarIntResult value) { +#ifdef USE_API_VARINT64 +bool ZWaveProxyRequest::decode_varint(uint32_t field_id, uint64_t value) { +#else +bool ZWaveProxyRequest::decode_varint(uint32_t field_id, uint32_t value) { +#endif switch (field_id) { case 1: - this->type = static_cast(value.as_uint32()); + this->type = static_cast(value); break; default: return false; @@ -3672,18 +3848,22 @@ uint32_t ListEntitiesInfraredResponse::calculate_size() const { } #endif #ifdef USE_IR_RF -bool InfraredRFTransmitRawTimingsRequest::decode_varint(uint32_t field_id, ProtoVarIntResult value) { +#ifdef USE_API_VARINT64 +bool InfraredRFTransmitRawTimingsRequest::decode_varint(uint32_t field_id, uint64_t value) { +#else +bool InfraredRFTransmitRawTimingsRequest::decode_varint(uint32_t field_id, uint32_t value) { +#endif switch (field_id) { #ifdef USE_DEVICES case 1: - this->device_id = value.as_uint32(); + this->device_id = value; break; #endif case 3: - this->carrier_frequency = value.as_uint32(); + this->carrier_frequency = value; break; case 4: - this->repeat_count = value.as_uint32(); + this->repeat_count = value; break; default: return false; @@ -3737,25 +3917,29 @@ uint32_t InfraredRFReceiveEvent::calculate_size() const { } #endif #ifdef USE_SERIAL_PROXY -bool SerialProxyConfigureRequest::decode_varint(uint32_t field_id, ProtoVarIntResult value) { +#ifdef USE_API_VARINT64 +bool SerialProxyConfigureRequest::decode_varint(uint32_t field_id, uint64_t value) { +#else +bool SerialProxyConfigureRequest::decode_varint(uint32_t field_id, uint32_t value) { +#endif switch (field_id) { case 1: - this->instance = value.as_uint32(); + this->instance = value; break; case 2: - this->baudrate = value.as_uint32(); + this->baudrate = value; break; case 3: - this->flow_control = value.as_bool(); + this->flow_control = value != 0; break; case 4: - this->parity = static_cast(value.as_uint32()); + this->parity = static_cast(value); break; case 5: - this->stop_bits = value.as_uint32(); + this->stop_bits = value; break; case 6: - this->data_size = value.as_uint32(); + this->data_size = value; break; default: return false; @@ -3772,10 +3956,14 @@ uint32_t SerialProxyDataReceived::calculate_size() const { size += ProtoSize::calc_length(1, this->data_len_); return size; } -bool SerialProxyWriteRequest::decode_varint(uint32_t field_id, ProtoVarIntResult value) { +#ifdef USE_API_VARINT64 +bool SerialProxyWriteRequest::decode_varint(uint32_t field_id, uint64_t value) { +#else +bool SerialProxyWriteRequest::decode_varint(uint32_t field_id, uint32_t value) { +#endif switch (field_id) { case 1: - this->instance = value.as_uint32(); + this->instance = value; break; default: return false; @@ -3794,23 +3982,31 @@ bool SerialProxyWriteRequest::decode_length(uint32_t field_id, ProtoLengthDelimi } return true; } -bool SerialProxySetModemPinsRequest::decode_varint(uint32_t field_id, ProtoVarIntResult value) { +#ifdef USE_API_VARINT64 +bool SerialProxySetModemPinsRequest::decode_varint(uint32_t field_id, uint64_t value) { +#else +bool SerialProxySetModemPinsRequest::decode_varint(uint32_t field_id, uint32_t value) { +#endif switch (field_id) { case 1: - this->instance = value.as_uint32(); + this->instance = value; break; case 2: - this->line_states = value.as_uint32(); + this->line_states = value; break; default: return false; } return true; } -bool SerialProxyGetModemPinsRequest::decode_varint(uint32_t field_id, ProtoVarIntResult value) { +#ifdef USE_API_VARINT64 +bool SerialProxyGetModemPinsRequest::decode_varint(uint32_t field_id, uint64_t value) { +#else +bool SerialProxyGetModemPinsRequest::decode_varint(uint32_t field_id, uint32_t value) { +#endif switch (field_id) { case 1: - this->instance = value.as_uint32(); + this->instance = value; break; default: return false; @@ -3827,13 +4023,17 @@ uint32_t SerialProxyGetModemPinsResponse::calculate_size() const { size += ProtoSize::calc_uint32(1, this->line_states); return size; } -bool SerialProxyRequest::decode_varint(uint32_t field_id, ProtoVarIntResult value) { +#ifdef USE_API_VARINT64 +bool SerialProxyRequest::decode_varint(uint32_t field_id, uint64_t value) { +#else +bool SerialProxyRequest::decode_varint(uint32_t field_id, uint32_t value) { +#endif switch (field_id) { case 1: - this->instance = value.as_uint32(); + this->instance = value; break; case 2: - this->type = static_cast(value.as_uint32()); + this->type = static_cast(value); break; default: return false; @@ -3856,22 +4056,26 @@ uint32_t SerialProxyRequestResponse::calculate_size() const { } #endif #ifdef USE_BLUETOOTH_PROXY -bool BluetoothSetConnectionParamsRequest::decode_varint(uint32_t field_id, ProtoVarIntResult value) { +#ifdef USE_API_VARINT64 +bool BluetoothSetConnectionParamsRequest::decode_varint(uint32_t field_id, uint64_t value) { +#else +bool BluetoothSetConnectionParamsRequest::decode_varint(uint32_t field_id, uint32_t value) { +#endif switch (field_id) { case 1: - this->address = value.as_uint64(); + this->address = value; break; case 2: - this->min_interval = value.as_uint32(); + this->min_interval = value; break; case 3: - this->max_interval = value.as_uint32(); + this->max_interval = value; break; case 4: - this->latency = value.as_uint32(); + this->latency = value; break; case 5: - this->timeout = value.as_uint32(); + this->timeout = value; break; default: return false; diff --git a/esphome/components/api/api_pb2.h b/esphome/components/api/api_pb2.h index c777140bda..de2c0002ae 100644 --- a/esphome/components/api/api_pb2.h +++ b/esphome/components/api/api_pb2.h @@ -399,7 +399,11 @@ class HelloRequest final : public ProtoDecodableMessage { protected: bool decode_length(uint32_t field_id, ProtoLengthDelimited value) override; - bool decode_varint(uint32_t field_id, ProtoVarIntResult value) override; +#ifdef USE_API_VARINT64 + bool decode_varint(uint32_t field_id, uint64_t value) override; +#else + bool decode_varint(uint32_t field_id, uint32_t value) override; +#endif }; class HelloResponse final : public ProtoMessage { public: @@ -688,7 +692,11 @@ class CoverCommandRequest final : public CommandProtoMessage { protected: bool decode_32bit(uint32_t field_id, Proto32Bit value) override; - bool decode_varint(uint32_t field_id, ProtoVarIntResult value) override; +#ifdef USE_API_VARINT64 + bool decode_varint(uint32_t field_id, uint64_t value) override; +#else + bool decode_varint(uint32_t field_id, uint32_t value) override; +#endif }; #endif #ifdef USE_FAN @@ -756,7 +764,11 @@ class FanCommandRequest final : public CommandProtoMessage { protected: bool decode_32bit(uint32_t field_id, Proto32Bit value) override; bool decode_length(uint32_t field_id, ProtoLengthDelimited value) override; - bool decode_varint(uint32_t field_id, ProtoVarIntResult value) override; +#ifdef USE_API_VARINT64 + bool decode_varint(uint32_t field_id, uint64_t value) override; +#else + bool decode_varint(uint32_t field_id, uint32_t value) override; +#endif }; #endif #ifdef USE_LIGHT @@ -846,7 +858,11 @@ class LightCommandRequest final : public CommandProtoMessage { protected: bool decode_32bit(uint32_t field_id, Proto32Bit value) override; bool decode_length(uint32_t field_id, ProtoLengthDelimited value) override; - bool decode_varint(uint32_t field_id, ProtoVarIntResult value) override; +#ifdef USE_API_VARINT64 + bool decode_varint(uint32_t field_id, uint64_t value) override; +#else + bool decode_varint(uint32_t field_id, uint32_t value) override; +#endif }; #endif #ifdef USE_SENSOR @@ -936,7 +952,11 @@ class SwitchCommandRequest final : public CommandProtoMessage { protected: bool decode_32bit(uint32_t field_id, Proto32Bit value) override; - bool decode_varint(uint32_t field_id, ProtoVarIntResult value) override; +#ifdef USE_API_VARINT64 + bool decode_varint(uint32_t field_id, uint64_t value) override; +#else + bool decode_varint(uint32_t field_id, uint32_t value) override; +#endif }; #endif #ifdef USE_TEXT_SENSOR @@ -988,7 +1008,11 @@ class SubscribeLogsRequest final : public ProtoDecodableMessage { #endif protected: - bool decode_varint(uint32_t field_id, ProtoVarIntResult value) override; +#ifdef USE_API_VARINT64 + bool decode_varint(uint32_t field_id, uint64_t value) override; +#else + bool decode_varint(uint32_t field_id, uint32_t value) override; +#endif }; class SubscribeLogsResponse final : public ProtoMessage { public: @@ -1110,7 +1134,11 @@ class HomeassistantActionResponse final : public ProtoDecodableMessage { protected: bool decode_length(uint32_t field_id, ProtoLengthDelimited value) override; - bool decode_varint(uint32_t field_id, ProtoVarIntResult value) override; +#ifdef USE_API_VARINT64 + bool decode_varint(uint32_t field_id, uint64_t value) override; +#else + bool decode_varint(uint32_t field_id, uint32_t value) override; +#endif }; #endif #ifdef USE_API_HOMEASSISTANT_STATES @@ -1176,7 +1204,11 @@ class DSTRule final : public ProtoDecodableMessage { #endif protected: - bool decode_varint(uint32_t field_id, ProtoVarIntResult value) override; +#ifdef USE_API_VARINT64 + bool decode_varint(uint32_t field_id, uint64_t value) override; +#else + bool decode_varint(uint32_t field_id, uint32_t value) override; +#endif }; class ParsedTimezone final : public ProtoDecodableMessage { public: @@ -1190,7 +1222,11 @@ class ParsedTimezone final : public ProtoDecodableMessage { protected: bool decode_length(uint32_t field_id, ProtoLengthDelimited value) override; - bool decode_varint(uint32_t field_id, ProtoVarIntResult value) override; +#ifdef USE_API_VARINT64 + bool decode_varint(uint32_t field_id, uint64_t value) override; +#else + bool decode_varint(uint32_t field_id, uint32_t value) override; +#endif }; class GetTimeResponse final : public ProtoDecodableMessage { public: @@ -1261,7 +1297,11 @@ class ExecuteServiceArgument final : public ProtoDecodableMessage { protected: bool decode_32bit(uint32_t field_id, Proto32Bit value) override; bool decode_length(uint32_t field_id, ProtoLengthDelimited value) override; - bool decode_varint(uint32_t field_id, ProtoVarIntResult value) override; +#ifdef USE_API_VARINT64 + bool decode_varint(uint32_t field_id, uint64_t value) override; +#else + bool decode_varint(uint32_t field_id, uint32_t value) override; +#endif }; class ExecuteServiceRequest final : public ProtoDecodableMessage { public: @@ -1286,7 +1326,11 @@ class ExecuteServiceRequest final : public ProtoDecodableMessage { protected: bool decode_32bit(uint32_t field_id, Proto32Bit value) override; bool decode_length(uint32_t field_id, ProtoLengthDelimited value) override; - bool decode_varint(uint32_t field_id, ProtoVarIntResult value) override; +#ifdef USE_API_VARINT64 + bool decode_varint(uint32_t field_id, uint64_t value) override; +#else + bool decode_varint(uint32_t field_id, uint32_t value) override; +#endif }; #endif #ifdef USE_API_USER_DEFINED_ACTION_RESPONSES @@ -1365,7 +1409,11 @@ class CameraImageRequest final : public ProtoDecodableMessage { #endif protected: - bool decode_varint(uint32_t field_id, ProtoVarIntResult value) override; +#ifdef USE_API_VARINT64 + bool decode_varint(uint32_t field_id, uint64_t value) override; +#else + bool decode_varint(uint32_t field_id, uint32_t value) override; +#endif }; #endif #ifdef USE_CLIMATE @@ -1464,7 +1512,11 @@ class ClimateCommandRequest final : public CommandProtoMessage { protected: bool decode_32bit(uint32_t field_id, Proto32Bit value) override; bool decode_length(uint32_t field_id, ProtoLengthDelimited value) override; - bool decode_varint(uint32_t field_id, ProtoVarIntResult value) override; +#ifdef USE_API_VARINT64 + bool decode_varint(uint32_t field_id, uint64_t value) override; +#else + bool decode_varint(uint32_t field_id, uint32_t value) override; +#endif }; #endif #ifdef USE_WATER_HEATER @@ -1528,7 +1580,11 @@ class WaterHeaterCommandRequest final : public CommandProtoMessage { protected: bool decode_32bit(uint32_t field_id, Proto32Bit value) override; - bool decode_varint(uint32_t field_id, ProtoVarIntResult value) override; +#ifdef USE_API_VARINT64 + bool decode_varint(uint32_t field_id, uint64_t value) override; +#else + bool decode_varint(uint32_t field_id, uint32_t value) override; +#endif }; #endif #ifdef USE_NUMBER @@ -1584,7 +1640,11 @@ class NumberCommandRequest final : public CommandProtoMessage { protected: bool decode_32bit(uint32_t field_id, Proto32Bit value) override; - bool decode_varint(uint32_t field_id, ProtoVarIntResult value) override; +#ifdef USE_API_VARINT64 + bool decode_varint(uint32_t field_id, uint64_t value) override; +#else + bool decode_varint(uint32_t field_id, uint32_t value) override; +#endif }; #endif #ifdef USE_SELECT @@ -1636,7 +1696,11 @@ class SelectCommandRequest final : public CommandProtoMessage { protected: bool decode_32bit(uint32_t field_id, Proto32Bit value) override; bool decode_length(uint32_t field_id, ProtoLengthDelimited value) override; - bool decode_varint(uint32_t field_id, ProtoVarIntResult value) override; +#ifdef USE_API_VARINT64 + bool decode_varint(uint32_t field_id, uint64_t value) override; +#else + bool decode_varint(uint32_t field_id, uint32_t value) override; +#endif }; #endif #ifdef USE_SIREN @@ -1696,7 +1760,11 @@ class SirenCommandRequest final : public CommandProtoMessage { protected: bool decode_32bit(uint32_t field_id, Proto32Bit value) override; bool decode_length(uint32_t field_id, ProtoLengthDelimited value) override; - bool decode_varint(uint32_t field_id, ProtoVarIntResult value) override; +#ifdef USE_API_VARINT64 + bool decode_varint(uint32_t field_id, uint64_t value) override; +#else + bool decode_varint(uint32_t field_id, uint32_t value) override; +#endif }; #endif #ifdef USE_LOCK @@ -1752,7 +1820,11 @@ class LockCommandRequest final : public CommandProtoMessage { protected: bool decode_32bit(uint32_t field_id, Proto32Bit value) override; bool decode_length(uint32_t field_id, ProtoLengthDelimited value) override; - bool decode_varint(uint32_t field_id, ProtoVarIntResult value) override; +#ifdef USE_API_VARINT64 + bool decode_varint(uint32_t field_id, uint64_t value) override; +#else + bool decode_varint(uint32_t field_id, uint32_t value) override; +#endif }; #endif #ifdef USE_BUTTON @@ -1785,7 +1857,11 @@ class ButtonCommandRequest final : public CommandProtoMessage { protected: bool decode_32bit(uint32_t field_id, Proto32Bit value) override; - bool decode_varint(uint32_t field_id, ProtoVarIntResult value) override; +#ifdef USE_API_VARINT64 + bool decode_varint(uint32_t field_id, uint64_t value) override; +#else + bool decode_varint(uint32_t field_id, uint32_t value) override; +#endif }; #endif #ifdef USE_MEDIA_PLAYER @@ -1862,7 +1938,11 @@ class MediaPlayerCommandRequest final : public CommandProtoMessage { protected: bool decode_32bit(uint32_t field_id, Proto32Bit value) override; bool decode_length(uint32_t field_id, ProtoLengthDelimited value) override; - bool decode_varint(uint32_t field_id, ProtoVarIntResult value) override; +#ifdef USE_API_VARINT64 + bool decode_varint(uint32_t field_id, uint64_t value) override; +#else + bool decode_varint(uint32_t field_id, uint32_t value) override; +#endif }; #endif #ifdef USE_BLUETOOTH_PROXY @@ -1879,7 +1959,11 @@ class SubscribeBluetoothLEAdvertisementsRequest final : public ProtoDecodableMes #endif protected: - bool decode_varint(uint32_t field_id, ProtoVarIntResult value) override; +#ifdef USE_API_VARINT64 + bool decode_varint(uint32_t field_id, uint64_t value) override; +#else + bool decode_varint(uint32_t field_id, uint32_t value) override; +#endif }; class BluetoothLERawAdvertisement final : public ProtoMessage { public: @@ -1929,7 +2013,11 @@ class BluetoothDeviceRequest final : public ProtoDecodableMessage { #endif protected: - bool decode_varint(uint32_t field_id, ProtoVarIntResult value) override; +#ifdef USE_API_VARINT64 + bool decode_varint(uint32_t field_id, uint64_t value) override; +#else + bool decode_varint(uint32_t field_id, uint32_t value) override; +#endif }; class BluetoothDeviceConnectionResponse final : public ProtoMessage { public: @@ -1963,7 +2051,11 @@ class BluetoothGATTGetServicesRequest final : public ProtoDecodableMessage { #endif protected: - bool decode_varint(uint32_t field_id, ProtoVarIntResult value) override; +#ifdef USE_API_VARINT64 + bool decode_varint(uint32_t field_id, uint64_t value) override; +#else + bool decode_varint(uint32_t field_id, uint32_t value) override; +#endif }; class BluetoothGATTDescriptor final : public ProtoMessage { public: @@ -2054,7 +2146,11 @@ class BluetoothGATTReadRequest final : public ProtoDecodableMessage { #endif protected: - bool decode_varint(uint32_t field_id, ProtoVarIntResult value) override; +#ifdef USE_API_VARINT64 + bool decode_varint(uint32_t field_id, uint64_t value) override; +#else + bool decode_varint(uint32_t field_id, uint32_t value) override; +#endif }; class BluetoothGATTReadResponse final : public ProtoMessage { public: @@ -2097,7 +2193,11 @@ class BluetoothGATTWriteRequest final : public ProtoDecodableMessage { protected: bool decode_length(uint32_t field_id, ProtoLengthDelimited value) override; - bool decode_varint(uint32_t field_id, ProtoVarIntResult value) override; +#ifdef USE_API_VARINT64 + bool decode_varint(uint32_t field_id, uint64_t value) override; +#else + bool decode_varint(uint32_t field_id, uint32_t value) override; +#endif }; class BluetoothGATTReadDescriptorRequest final : public ProtoDecodableMessage { public: @@ -2113,7 +2213,11 @@ class BluetoothGATTReadDescriptorRequest final : public ProtoDecodableMessage { #endif protected: - bool decode_varint(uint32_t field_id, ProtoVarIntResult value) override; +#ifdef USE_API_VARINT64 + bool decode_varint(uint32_t field_id, uint64_t value) override; +#else + bool decode_varint(uint32_t field_id, uint32_t value) override; +#endif }; class BluetoothGATTWriteDescriptorRequest final : public ProtoDecodableMessage { public: @@ -2132,7 +2236,11 @@ class BluetoothGATTWriteDescriptorRequest final : public ProtoDecodableMessage { protected: bool decode_length(uint32_t field_id, ProtoLengthDelimited value) override; - bool decode_varint(uint32_t field_id, ProtoVarIntResult value) override; +#ifdef USE_API_VARINT64 + bool decode_varint(uint32_t field_id, uint64_t value) override; +#else + bool decode_varint(uint32_t field_id, uint32_t value) override; +#endif }; class BluetoothGATTNotifyRequest final : public ProtoDecodableMessage { public: @@ -2149,7 +2257,11 @@ class BluetoothGATTNotifyRequest final : public ProtoDecodableMessage { #endif protected: - bool decode_varint(uint32_t field_id, ProtoVarIntResult value) override; +#ifdef USE_API_VARINT64 + bool decode_varint(uint32_t field_id, uint64_t value) override; +#else + bool decode_varint(uint32_t field_id, uint32_t value) override; +#endif }; class BluetoothGATTNotifyDataResponse final : public ProtoMessage { public: @@ -2329,7 +2441,11 @@ class BluetoothScannerSetModeRequest final : public ProtoDecodableMessage { #endif protected: - bool decode_varint(uint32_t field_id, ProtoVarIntResult value) override; +#ifdef USE_API_VARINT64 + bool decode_varint(uint32_t field_id, uint64_t value) override; +#else + bool decode_varint(uint32_t field_id, uint32_t value) override; +#endif }; #endif #ifdef USE_VOICE_ASSISTANT @@ -2347,7 +2463,11 @@ class SubscribeVoiceAssistantRequest final : public ProtoDecodableMessage { #endif protected: - bool decode_varint(uint32_t field_id, ProtoVarIntResult value) override; +#ifdef USE_API_VARINT64 + bool decode_varint(uint32_t field_id, uint64_t value) override; +#else + bool decode_varint(uint32_t field_id, uint32_t value) override; +#endif }; class VoiceAssistantAudioSettings final : public ProtoMessage { public: @@ -2396,7 +2516,11 @@ class VoiceAssistantResponse final : public ProtoDecodableMessage { #endif protected: - bool decode_varint(uint32_t field_id, ProtoVarIntResult value) override; +#ifdef USE_API_VARINT64 + bool decode_varint(uint32_t field_id, uint64_t value) override; +#else + bool decode_varint(uint32_t field_id, uint32_t value) override; +#endif }; class VoiceAssistantEventData final : public ProtoDecodableMessage { public: @@ -2424,7 +2548,11 @@ class VoiceAssistantEventResponse final : public ProtoDecodableMessage { protected: bool decode_length(uint32_t field_id, ProtoLengthDelimited value) override; - bool decode_varint(uint32_t field_id, ProtoVarIntResult value) override; +#ifdef USE_API_VARINT64 + bool decode_varint(uint32_t field_id, uint64_t value) override; +#else + bool decode_varint(uint32_t field_id, uint32_t value) override; +#endif }; class VoiceAssistantAudio final : public ProtoDecodableMessage { public: @@ -2444,7 +2572,11 @@ class VoiceAssistantAudio final : public ProtoDecodableMessage { protected: bool decode_length(uint32_t field_id, ProtoLengthDelimited value) override; - bool decode_varint(uint32_t field_id, ProtoVarIntResult value) override; +#ifdef USE_API_VARINT64 + bool decode_varint(uint32_t field_id, uint64_t value) override; +#else + bool decode_varint(uint32_t field_id, uint32_t value) override; +#endif }; class VoiceAssistantTimerEventResponse final : public ProtoDecodableMessage { public: @@ -2465,7 +2597,11 @@ class VoiceAssistantTimerEventResponse final : public ProtoDecodableMessage { protected: bool decode_length(uint32_t field_id, ProtoLengthDelimited value) override; - bool decode_varint(uint32_t field_id, ProtoVarIntResult value) override; +#ifdef USE_API_VARINT64 + bool decode_varint(uint32_t field_id, uint64_t value) override; +#else + bool decode_varint(uint32_t field_id, uint32_t value) override; +#endif }; class VoiceAssistantAnnounceRequest final : public ProtoDecodableMessage { public: @@ -2484,7 +2620,11 @@ class VoiceAssistantAnnounceRequest final : public ProtoDecodableMessage { protected: bool decode_length(uint32_t field_id, ProtoLengthDelimited value) override; - bool decode_varint(uint32_t field_id, ProtoVarIntResult value) override; +#ifdef USE_API_VARINT64 + bool decode_varint(uint32_t field_id, uint64_t value) override; +#else + bool decode_varint(uint32_t field_id, uint32_t value) override; +#endif }; class VoiceAssistantAnnounceFinished final : public ProtoMessage { public: @@ -2530,7 +2670,11 @@ class VoiceAssistantExternalWakeWord final : public ProtoDecodableMessage { protected: bool decode_length(uint32_t field_id, ProtoLengthDelimited value) override; - bool decode_varint(uint32_t field_id, ProtoVarIntResult value) override; +#ifdef USE_API_VARINT64 + bool decode_varint(uint32_t field_id, uint64_t value) override; +#else + bool decode_varint(uint32_t field_id, uint32_t value) override; +#endif }; class VoiceAssistantConfigurationRequest final : public ProtoDecodableMessage { public: @@ -2632,7 +2776,11 @@ class AlarmControlPanelCommandRequest final : public CommandProtoMessage { protected: bool decode_32bit(uint32_t field_id, Proto32Bit value) override; bool decode_length(uint32_t field_id, ProtoLengthDelimited value) override; - bool decode_varint(uint32_t field_id, ProtoVarIntResult value) override; +#ifdef USE_API_VARINT64 + bool decode_varint(uint32_t field_id, uint64_t value) override; +#else + bool decode_varint(uint32_t field_id, uint32_t value) override; +#endif }; #endif #ifdef USE_TEXT @@ -2687,7 +2835,11 @@ class TextCommandRequest final : public CommandProtoMessage { protected: bool decode_32bit(uint32_t field_id, Proto32Bit value) override; bool decode_length(uint32_t field_id, ProtoLengthDelimited value) override; - bool decode_varint(uint32_t field_id, ProtoVarIntResult value) override; +#ifdef USE_API_VARINT64 + bool decode_varint(uint32_t field_id, uint64_t value) override; +#else + bool decode_varint(uint32_t field_id, uint32_t value) override; +#endif }; #endif #ifdef USE_DATETIME_DATE @@ -2741,7 +2893,11 @@ class DateCommandRequest final : public CommandProtoMessage { protected: bool decode_32bit(uint32_t field_id, Proto32Bit value) override; - bool decode_varint(uint32_t field_id, ProtoVarIntResult value) override; +#ifdef USE_API_VARINT64 + bool decode_varint(uint32_t field_id, uint64_t value) override; +#else + bool decode_varint(uint32_t field_id, uint32_t value) override; +#endif }; #endif #ifdef USE_DATETIME_TIME @@ -2795,7 +2951,11 @@ class TimeCommandRequest final : public CommandProtoMessage { protected: bool decode_32bit(uint32_t field_id, Proto32Bit value) override; - bool decode_varint(uint32_t field_id, ProtoVarIntResult value) override; +#ifdef USE_API_VARINT64 + bool decode_varint(uint32_t field_id, uint64_t value) override; +#else + bool decode_varint(uint32_t field_id, uint32_t value) override; +#endif }; #endif #ifdef USE_EVENT @@ -2886,7 +3046,11 @@ class ValveCommandRequest final : public CommandProtoMessage { protected: bool decode_32bit(uint32_t field_id, Proto32Bit value) override; - bool decode_varint(uint32_t field_id, ProtoVarIntResult value) override; +#ifdef USE_API_VARINT64 + bool decode_varint(uint32_t field_id, uint64_t value) override; +#else + bool decode_varint(uint32_t field_id, uint32_t value) override; +#endif }; #endif #ifdef USE_DATETIME_DATETIME @@ -2936,7 +3100,11 @@ class DateTimeCommandRequest final : public CommandProtoMessage { protected: bool decode_32bit(uint32_t field_id, Proto32Bit value) override; - bool decode_varint(uint32_t field_id, ProtoVarIntResult value) override; +#ifdef USE_API_VARINT64 + bool decode_varint(uint32_t field_id, uint64_t value) override; +#else + bool decode_varint(uint32_t field_id, uint32_t value) override; +#endif }; #endif #ifdef USE_UPDATE @@ -2994,7 +3162,11 @@ class UpdateCommandRequest final : public CommandProtoMessage { protected: bool decode_32bit(uint32_t field_id, Proto32Bit value) override; - bool decode_varint(uint32_t field_id, ProtoVarIntResult value) override; +#ifdef USE_API_VARINT64 + bool decode_varint(uint32_t field_id, uint64_t value) override; +#else + bool decode_varint(uint32_t field_id, uint32_t value) override; +#endif }; #endif #ifdef USE_ZWAVE_PROXY @@ -3034,7 +3206,11 @@ class ZWaveProxyRequest final : public ProtoDecodableMessage { protected: bool decode_length(uint32_t field_id, ProtoLengthDelimited value) override; - bool decode_varint(uint32_t field_id, ProtoVarIntResult value) override; +#ifdef USE_API_VARINT64 + bool decode_varint(uint32_t field_id, uint64_t value) override; +#else + bool decode_varint(uint32_t field_id, uint32_t value) override; +#endif }; #endif #ifdef USE_INFRARED @@ -3079,7 +3255,11 @@ class InfraredRFTransmitRawTimingsRequest final : public ProtoDecodableMessage { protected: bool decode_32bit(uint32_t field_id, Proto32Bit value) override; bool decode_length(uint32_t field_id, ProtoLengthDelimited value) override; - bool decode_varint(uint32_t field_id, ProtoVarIntResult value) override; +#ifdef USE_API_VARINT64 + bool decode_varint(uint32_t field_id, uint64_t value) override; +#else + bool decode_varint(uint32_t field_id, uint32_t value) override; +#endif }; class InfraredRFReceiveEvent final : public ProtoMessage { public: @@ -3121,7 +3301,11 @@ class SerialProxyConfigureRequest final : public ProtoDecodableMessage { #endif protected: - bool decode_varint(uint32_t field_id, ProtoVarIntResult value) override; +#ifdef USE_API_VARINT64 + bool decode_varint(uint32_t field_id, uint64_t value) override; +#else + bool decode_varint(uint32_t field_id, uint32_t value) override; +#endif }; class SerialProxyDataReceived final : public ProtoMessage { public: @@ -3161,7 +3345,11 @@ class SerialProxyWriteRequest final : public ProtoDecodableMessage { protected: bool decode_length(uint32_t field_id, ProtoLengthDelimited value) override; - bool decode_varint(uint32_t field_id, ProtoVarIntResult value) override; +#ifdef USE_API_VARINT64 + bool decode_varint(uint32_t field_id, uint64_t value) override; +#else + bool decode_varint(uint32_t field_id, uint32_t value) override; +#endif }; class SerialProxySetModemPinsRequest final : public ProtoDecodableMessage { public: @@ -3177,7 +3365,11 @@ class SerialProxySetModemPinsRequest final : public ProtoDecodableMessage { #endif protected: - bool decode_varint(uint32_t field_id, ProtoVarIntResult value) override; +#ifdef USE_API_VARINT64 + bool decode_varint(uint32_t field_id, uint64_t value) override; +#else + bool decode_varint(uint32_t field_id, uint32_t value) override; +#endif }; class SerialProxyGetModemPinsRequest final : public ProtoDecodableMessage { public: @@ -3192,7 +3384,11 @@ class SerialProxyGetModemPinsRequest final : public ProtoDecodableMessage { #endif protected: - bool decode_varint(uint32_t field_id, ProtoVarIntResult value) override; +#ifdef USE_API_VARINT64 + bool decode_varint(uint32_t field_id, uint64_t value) override; +#else + bool decode_varint(uint32_t field_id, uint32_t value) override; +#endif }; class SerialProxyGetModemPinsResponse final : public ProtoMessage { public: @@ -3225,7 +3421,11 @@ class SerialProxyRequest final : public ProtoDecodableMessage { #endif protected: - bool decode_varint(uint32_t field_id, ProtoVarIntResult value) override; +#ifdef USE_API_VARINT64 + bool decode_varint(uint32_t field_id, uint64_t value) override; +#else + bool decode_varint(uint32_t field_id, uint32_t value) override; +#endif }; class SerialProxyRequestResponse final : public ProtoMessage { public: @@ -3265,7 +3465,11 @@ class BluetoothSetConnectionParamsRequest final : public ProtoDecodableMessage { #endif protected: - bool decode_varint(uint32_t field_id, ProtoVarIntResult value) override; +#ifdef USE_API_VARINT64 + bool decode_varint(uint32_t field_id, uint64_t value) override; +#else + bool decode_varint(uint32_t field_id, uint32_t value) override; +#endif }; class BluetoothSetConnectionParamsResponse final : public ProtoMessage { public: diff --git a/esphome/components/api/proto.cpp b/esphome/components/api/proto.cpp index 5dbeae7758..e03cc69348 100644 --- a/esphome/components/api/proto.cpp +++ b/esphome/components/api/proto.cpp @@ -227,7 +227,11 @@ void ProtoDecodableMessage::decode(const uint8_t *buffer, size_t length) { ESP_LOGV(TAG, "Invalid VarInt at offset %ld", (long) (ptr - buffer)); return; } - if (!this->decode_varint(field_id, res)) { +#ifdef USE_API_VARINT64 + if (!this->decode_varint(field_id, res.as_uint64())) { +#else + if (!this->decode_varint(field_id, res.as_uint32())) { +#endif ESP_LOGV(TAG, "Cannot decode VarInt field %" PRIu32 " with value %" PRIu32 "!", field_id, res.as_uint32()); } ptr += res.consumed; diff --git a/esphome/components/api/proto.h b/esphome/components/api/proto.h index 86746c949f..7da4dc9bdc 100644 --- a/esphome/components/api/proto.h +++ b/esphome/components/api/proto.h @@ -506,7 +506,11 @@ class ProtoDecodableMessage : public ProtoMessage { protected: ~ProtoDecodableMessage() = default; - virtual bool decode_varint(uint32_t field_id, ProtoVarIntResult value) { return false; } +#ifdef USE_API_VARINT64 + virtual bool decode_varint(uint32_t field_id, uint64_t value) { return false; } +#else + virtual bool decode_varint(uint32_t field_id, uint32_t value) { return false; } +#endif virtual bool decode_length(uint32_t field_id, ProtoLengthDelimited value) { return false; } virtual bool decode_32bit(uint32_t field_id, Proto32Bit value) { return false; } // NOTE: decode_64bit removed - wire type 1 not supported diff --git a/script/api_protobuf/api_protobuf.py b/script/api_protobuf/api_protobuf.py index bf1d34d67f..2febe2580e 100755 --- a/script/api_protobuf/api_protobuf.py +++ b/script/api_protobuf/api_protobuf.py @@ -193,6 +193,7 @@ class TypeInfo(ABC): return f"case {self.number}: this->{self.field_name} = {content}; break;" decode_varint = None + is_varint64 = False @property def decode_length_content(self) -> str: @@ -461,7 +462,8 @@ class FloatType(TypeInfo): class Int64Type(TypeInfo): cpp_type = "int64_t" default_value = "0" - decode_varint = "value.as_int64()" + decode_varint = "static_cast(value)" + is_varint64 = True encode_func = "encode_int64" wire_type = WireType.VARINT # Uses wire type 0 @@ -481,7 +483,8 @@ class Int64Type(TypeInfo): class UInt64Type(TypeInfo): cpp_type = "uint64_t" default_value = "0" - decode_varint = "value.as_uint64()" + decode_varint = "value" + is_varint64 = True encode_func = "encode_uint64" wire_type = WireType.VARINT # Uses wire type 0 @@ -501,7 +504,7 @@ class UInt64Type(TypeInfo): class Int32Type(TypeInfo): cpp_type = "int32_t" default_value = "0" - decode_varint = "value.as_int32()" + decode_varint = "static_cast(value)" encode_func = "encode_int32" wire_type = WireType.VARINT # Uses wire type 0 @@ -573,7 +576,7 @@ class Fixed32Type(TypeInfo): class BoolType(TypeInfo): cpp_type = "bool" default_value = "false" - decode_varint = "value.as_bool()" + decode_varint = "value != 0" encode_func = "encode_bool" wire_type = WireType.VARINT # Uses wire type 0 @@ -1151,7 +1154,7 @@ class FixedArrayBytesType(TypeInfo): class UInt32Type(TypeInfo): cpp_type = "uint32_t" default_value = "0" - decode_varint = "value.as_uint32()" + decode_varint = "value" encode_func = "encode_uint32" wire_type = WireType.VARINT # Uses wire type 0 @@ -1175,7 +1178,7 @@ class EnumType(TypeInfo): @property def decode_varint(self) -> str: - return f"static_cast<{self.cpp_type}>(value.as_uint32())" + return f"static_cast<{self.cpp_type}>(value)" default_value = "" wire_type = WireType.VARINT # Uses wire type 0 @@ -1262,7 +1265,7 @@ class SFixed64Type(TypeInfo): class SInt32Type(TypeInfo): cpp_type = "int32_t" default_value = "0" - decode_varint = "value.as_sint32()" + decode_varint = "decode_zigzag32(value)" encode_func = "encode_sint32" wire_type = WireType.VARINT # Uses wire type 0 @@ -1282,7 +1285,8 @@ class SInt32Type(TypeInfo): class SInt64Type(TypeInfo): cpp_type = "int64_t" default_value = "0" - decode_varint = "value.as_sint64()" + decode_varint = "decode_zigzag64(value)" + is_varint64 = True encode_func = "encode_sint64" wire_type = WireType.VARINT # Uses wire type 0 @@ -1620,6 +1624,10 @@ class RepeatedTypeInfo(TypeInfo): """ return self._ti.wire_type + @property + def is_varint64(self): + return self._ti.is_varint64 + @property def decode_varint_content(self) -> str: # Pointer fields don't support decoding @@ -2205,7 +2213,12 @@ def build_message_type( cpp = "" if decode_varint: - o = f"bool {desc.name}::decode_varint(uint32_t field_id, ProtoVarIntResult value) {{\n" + # Use conditional parameter type to match base class + o = "#ifdef USE_API_VARINT64\n" + o += f"bool {desc.name}::decode_varint(uint32_t field_id, uint64_t value) {{\n" + o += "#else\n" + o += f"bool {desc.name}::decode_varint(uint32_t field_id, uint32_t value) {{\n" + o += "#endif\n" o += " switch (field_id) {\n" o += indent("\n".join(decode_varint), " ") + "\n" o += " default: return false;\n" @@ -2213,10 +2226,15 @@ def build_message_type( o += " return true;\n" o += "}\n" cpp += o - prot = ( - "bool decode_varint(uint32_t field_id, ProtoVarIntResult value) override;" - ) - protected_content.insert(0, prot) + prot_lines = [ + "#ifdef USE_API_VARINT64", + "bool decode_varint(uint32_t field_id, uint64_t value) override;", + "#else", + "bool decode_varint(uint32_t field_id, uint32_t value) override;", + "#endif", + ] + for i, line in enumerate(prot_lines): + protected_content.insert(i, line) if decode_length: o = f"bool {desc.name}::decode_length(uint32_t field_id, ProtoLengthDelimited value) {{\n" o += " switch (field_id) {\n" From b838085e419fd49ee826e9cad4ab2e663f58fe00 Mon Sep 17 00:00:00 2001 From: "J. Nick Koston" Date: Sun, 8 Mar 2026 18:56:15 -1000 Subject: [PATCH 11/15] [api] Use proto_varint_value_t type alias instead of #ifdef blocks Replace per-override #ifdef USE_API_VARINT64 conditionals with a single type alias proto_varint_value_t, eliminating preprocessor blocks from every decode_varint signature in api_pb2.cpp/h. Co-Authored-By: Claude Opus 4.6 --- esphome/components/api/api_pb2.cpp | 306 +++++----------------------- esphome/components/api/api_pb2.h | 306 +++++----------------------- esphome/components/api/proto.cpp | 6 +- esphome/components/api/proto.h | 19 +- script/api_protobuf/api_protobuf.py | 18 +- 5 files changed, 115 insertions(+), 540 deletions(-) diff --git a/esphome/components/api/api_pb2.cpp b/esphome/components/api/api_pb2.cpp index 2458c4b2a5..20ee65fd04 100644 --- a/esphome/components/api/api_pb2.cpp +++ b/esphome/components/api/api_pb2.cpp @@ -7,11 +7,7 @@ namespace esphome::api { -#ifdef USE_API_VARINT64 -bool HelloRequest::decode_varint(uint32_t field_id, uint64_t value) { -#else -bool HelloRequest::decode_varint(uint32_t field_id, uint32_t value) { -#endif +bool HelloRequest::decode_varint(uint32_t field_id, proto_varint_value_t value) { switch (field_id) { case 2: this->api_version_major = value; @@ -320,11 +316,7 @@ uint32_t CoverStateResponse::calculate_size() const { #endif return size; } -#ifdef USE_API_VARINT64 -bool CoverCommandRequest::decode_varint(uint32_t field_id, uint64_t value) { -#else -bool CoverCommandRequest::decode_varint(uint32_t field_id, uint32_t value) { -#endif +bool CoverCommandRequest::decode_varint(uint32_t field_id, proto_varint_value_t value) { switch (field_id) { case 4: this->has_position = value != 0; @@ -431,11 +423,7 @@ uint32_t FanStateResponse::calculate_size() const { #endif return size; } -#ifdef USE_API_VARINT64 -bool FanCommandRequest::decode_varint(uint32_t field_id, uint64_t value) { -#else -bool FanCommandRequest::decode_varint(uint32_t field_id, uint32_t value) { -#endif +bool FanCommandRequest::decode_varint(uint32_t field_id, proto_varint_value_t value) { switch (field_id) { case 2: this->has_state = value != 0; @@ -583,11 +571,7 @@ uint32_t LightStateResponse::calculate_size() const { #endif return size; } -#ifdef USE_API_VARINT64 -bool LightCommandRequest::decode_varint(uint32_t field_id, uint64_t value) { -#else -bool LightCommandRequest::decode_varint(uint32_t field_id, uint32_t value) { -#endif +bool LightCommandRequest::decode_varint(uint32_t field_id, proto_varint_value_t value) { switch (field_id) { case 2: this->has_state = value != 0; @@ -803,11 +787,7 @@ uint32_t SwitchStateResponse::calculate_size() const { #endif return size; } -#ifdef USE_API_VARINT64 -bool SwitchCommandRequest::decode_varint(uint32_t field_id, uint64_t value) { -#else -bool SwitchCommandRequest::decode_varint(uint32_t field_id, uint32_t value) { -#endif +bool SwitchCommandRequest::decode_varint(uint32_t field_id, proto_varint_value_t value) { switch (field_id) { case 2: this->state = value != 0; @@ -883,11 +863,7 @@ uint32_t TextSensorStateResponse::calculate_size() const { return size; } #endif -#ifdef USE_API_VARINT64 -bool SubscribeLogsRequest::decode_varint(uint32_t field_id, uint64_t value) { -#else -bool SubscribeLogsRequest::decode_varint(uint32_t field_id, uint32_t value) { -#endif +bool SubscribeLogsRequest::decode_varint(uint32_t field_id, proto_varint_value_t value) { switch (field_id) { case 1: this->level = static_cast(value); @@ -995,11 +971,7 @@ uint32_t HomeassistantActionRequest::calculate_size() const { } #endif #ifdef USE_API_HOMEASSISTANT_ACTION_RESPONSES -#ifdef USE_API_VARINT64 -bool HomeassistantActionResponse::decode_varint(uint32_t field_id, uint64_t value) { -#else -bool HomeassistantActionResponse::decode_varint(uint32_t field_id, uint32_t value) { -#endif +bool HomeassistantActionResponse::decode_varint(uint32_t field_id, proto_varint_value_t value) { switch (field_id) { case 1: this->call_id = value; @@ -1064,11 +1036,7 @@ bool HomeAssistantStateResponse::decode_length(uint32_t field_id, ProtoLengthDel return true; } #endif -#ifdef USE_API_VARINT64 -bool DSTRule::decode_varint(uint32_t field_id, uint64_t value) { -#else -bool DSTRule::decode_varint(uint32_t field_id, uint32_t value) { -#endif +bool DSTRule::decode_varint(uint32_t field_id, proto_varint_value_t value) { switch (field_id) { case 1: this->time_seconds = decode_zigzag32(value); @@ -1093,11 +1061,7 @@ bool DSTRule::decode_varint(uint32_t field_id, uint32_t value) { } return true; } -#ifdef USE_API_VARINT64 -bool ParsedTimezone::decode_varint(uint32_t field_id, uint64_t value) { -#else -bool ParsedTimezone::decode_varint(uint32_t field_id, uint32_t value) { -#endif +bool ParsedTimezone::decode_varint(uint32_t field_id, proto_varint_value_t value) { switch (field_id) { case 1: this->std_offset_seconds = decode_zigzag32(value); @@ -1178,11 +1142,7 @@ uint32_t ListEntitiesServicesResponse::calculate_size() const { size += ProtoSize::calc_uint32(1, static_cast(this->supports_response)); return size; } -#ifdef USE_API_VARINT64 -bool ExecuteServiceArgument::decode_varint(uint32_t field_id, uint64_t value) { -#else -bool ExecuteServiceArgument::decode_varint(uint32_t field_id, uint32_t value) { -#endif +bool ExecuteServiceArgument::decode_varint(uint32_t field_id, proto_varint_value_t value) { switch (field_id) { case 1: this->bool_ = value != 0; @@ -1242,11 +1202,7 @@ void ExecuteServiceArgument::decode(const uint8_t *buffer, size_t length) { this->string_array.init(count_string_array); ProtoDecodableMessage::decode(buffer, length); } -#ifdef USE_API_VARINT64 -bool ExecuteServiceRequest::decode_varint(uint32_t field_id, uint64_t value) { -#else -bool ExecuteServiceRequest::decode_varint(uint32_t field_id, uint32_t value) { -#endif +bool ExecuteServiceRequest::decode_varint(uint32_t field_id, proto_varint_value_t value) { switch (field_id) { #ifdef USE_API_USER_DEFINED_ACTION_RESPONSES case 3: @@ -1357,11 +1313,7 @@ uint32_t CameraImageResponse::calculate_size() const { #endif return size; } -#ifdef USE_API_VARINT64 -bool CameraImageRequest::decode_varint(uint32_t field_id, uint64_t value) { -#else -bool CameraImageRequest::decode_varint(uint32_t field_id, uint32_t value) { -#endif +bool CameraImageRequest::decode_varint(uint32_t field_id, proto_varint_value_t value) { switch (field_id) { case 1: this->single = value != 0; @@ -1516,11 +1468,7 @@ uint32_t ClimateStateResponse::calculate_size() const { #endif return size; } -#ifdef USE_API_VARINT64 -bool ClimateCommandRequest::decode_varint(uint32_t field_id, uint64_t value) { -#else -bool ClimateCommandRequest::decode_varint(uint32_t field_id, uint32_t value) { -#endif +bool ClimateCommandRequest::decode_varint(uint32_t field_id, proto_varint_value_t value) { switch (field_id) { case 2: this->has_mode = value != 0; @@ -1683,11 +1631,7 @@ uint32_t WaterHeaterStateResponse::calculate_size() const { size += ProtoSize::calc_float(1, this->target_temperature_high); return size; } -#ifdef USE_API_VARINT64 -bool WaterHeaterCommandRequest::decode_varint(uint32_t field_id, uint64_t value) { -#else -bool WaterHeaterCommandRequest::decode_varint(uint32_t field_id, uint32_t value) { -#endif +bool WaterHeaterCommandRequest::decode_varint(uint32_t field_id, proto_varint_value_t value) { switch (field_id) { case 2: this->has_fields = value; @@ -1787,11 +1731,7 @@ uint32_t NumberStateResponse::calculate_size() const { #endif return size; } -#ifdef USE_API_VARINT64 -bool NumberCommandRequest::decode_varint(uint32_t field_id, uint64_t value) { -#else -bool NumberCommandRequest::decode_varint(uint32_t field_id, uint32_t value) { -#endif +bool NumberCommandRequest::decode_varint(uint32_t field_id, proto_varint_value_t value) { switch (field_id) { #ifdef USE_DEVICES case 3: @@ -1872,11 +1812,7 @@ uint32_t SelectStateResponse::calculate_size() const { #endif return size; } -#ifdef USE_API_VARINT64 -bool SelectCommandRequest::decode_varint(uint32_t field_id, uint64_t value) { -#else -bool SelectCommandRequest::decode_varint(uint32_t field_id, uint32_t value) { -#endif +bool SelectCommandRequest::decode_varint(uint32_t field_id, proto_varint_value_t value) { switch (field_id) { #ifdef USE_DEVICES case 3: @@ -1967,11 +1903,7 @@ uint32_t SirenStateResponse::calculate_size() const { #endif return size; } -#ifdef USE_API_VARINT64 -bool SirenCommandRequest::decode_varint(uint32_t field_id, uint64_t value) { -#else -bool SirenCommandRequest::decode_varint(uint32_t field_id, uint32_t value) { -#endif +bool SirenCommandRequest::decode_varint(uint32_t field_id, proto_varint_value_t value) { switch (field_id) { case 2: this->has_state = value != 0; @@ -2079,11 +2011,7 @@ uint32_t LockStateResponse::calculate_size() const { #endif return size; } -#ifdef USE_API_VARINT64 -bool LockCommandRequest::decode_varint(uint32_t field_id, uint64_t value) { -#else -bool LockCommandRequest::decode_varint(uint32_t field_id, uint32_t value) { -#endif +bool LockCommandRequest::decode_varint(uint32_t field_id, proto_varint_value_t value) { switch (field_id) { case 2: this->command = static_cast(value); @@ -2154,11 +2082,7 @@ uint32_t ListEntitiesButtonResponse::calculate_size() const { #endif return size; } -#ifdef USE_API_VARINT64 -bool ButtonCommandRequest::decode_varint(uint32_t field_id, uint64_t value) { -#else -bool ButtonCommandRequest::decode_varint(uint32_t field_id, uint32_t value) { -#endif +bool ButtonCommandRequest::decode_varint(uint32_t field_id, proto_varint_value_t value) { switch (field_id) { #ifdef USE_DEVICES case 2: @@ -2258,11 +2182,7 @@ uint32_t MediaPlayerStateResponse::calculate_size() const { #endif return size; } -#ifdef USE_API_VARINT64 -bool MediaPlayerCommandRequest::decode_varint(uint32_t field_id, uint64_t value) { -#else -bool MediaPlayerCommandRequest::decode_varint(uint32_t field_id, uint32_t value) { -#endif +bool MediaPlayerCommandRequest::decode_varint(uint32_t field_id, proto_varint_value_t value) { switch (field_id) { case 2: this->has_command = value != 0; @@ -2318,11 +2238,7 @@ bool MediaPlayerCommandRequest::decode_32bit(uint32_t field_id, Proto32Bit value } #endif #ifdef USE_BLUETOOTH_PROXY -#ifdef USE_API_VARINT64 -bool SubscribeBluetoothLEAdvertisementsRequest::decode_varint(uint32_t field_id, uint64_t value) { -#else -bool SubscribeBluetoothLEAdvertisementsRequest::decode_varint(uint32_t field_id, uint32_t value) { -#endif +bool SubscribeBluetoothLEAdvertisementsRequest::decode_varint(uint32_t field_id, proto_varint_value_t value) { switch (field_id) { case 1: this->flags = value; @@ -2358,11 +2274,7 @@ uint32_t BluetoothLERawAdvertisementsResponse::calculate_size() const { } return size; } -#ifdef USE_API_VARINT64 -bool BluetoothDeviceRequest::decode_varint(uint32_t field_id, uint64_t value) { -#else -bool BluetoothDeviceRequest::decode_varint(uint32_t field_id, uint32_t value) { -#endif +bool BluetoothDeviceRequest::decode_varint(uint32_t field_id, proto_varint_value_t value) { switch (field_id) { case 1: this->address = value; @@ -2395,11 +2307,7 @@ uint32_t BluetoothDeviceConnectionResponse::calculate_size() const { size += ProtoSize::calc_int32(1, this->error); return size; } -#ifdef USE_API_VARINT64 -bool BluetoothGATTGetServicesRequest::decode_varint(uint32_t field_id, uint64_t value) { -#else -bool BluetoothGATTGetServicesRequest::decode_varint(uint32_t field_id, uint32_t value) { -#endif +bool BluetoothGATTGetServicesRequest::decode_varint(uint32_t field_id, proto_varint_value_t value) { switch (field_id) { case 1: this->address = value; @@ -2505,11 +2413,7 @@ uint32_t BluetoothGATTGetServicesDoneResponse::calculate_size() const { size += ProtoSize::calc_uint64(1, this->address); return size; } -#ifdef USE_API_VARINT64 -bool BluetoothGATTReadRequest::decode_varint(uint32_t field_id, uint64_t value) { -#else -bool BluetoothGATTReadRequest::decode_varint(uint32_t field_id, uint32_t value) { -#endif +bool BluetoothGATTReadRequest::decode_varint(uint32_t field_id, proto_varint_value_t value) { switch (field_id) { case 1: this->address = value; @@ -2534,11 +2438,7 @@ uint32_t BluetoothGATTReadResponse::calculate_size() const { size += ProtoSize::calc_length(1, this->data_len_); return size; } -#ifdef USE_API_VARINT64 -bool BluetoothGATTWriteRequest::decode_varint(uint32_t field_id, uint64_t value) { -#else -bool BluetoothGATTWriteRequest::decode_varint(uint32_t field_id, uint32_t value) { -#endif +bool BluetoothGATTWriteRequest::decode_varint(uint32_t field_id, proto_varint_value_t value) { switch (field_id) { case 1: this->address = value; @@ -2566,11 +2466,7 @@ bool BluetoothGATTWriteRequest::decode_length(uint32_t field_id, ProtoLengthDeli } return true; } -#ifdef USE_API_VARINT64 -bool BluetoothGATTReadDescriptorRequest::decode_varint(uint32_t field_id, uint64_t value) { -#else -bool BluetoothGATTReadDescriptorRequest::decode_varint(uint32_t field_id, uint32_t value) { -#endif +bool BluetoothGATTReadDescriptorRequest::decode_varint(uint32_t field_id, proto_varint_value_t value) { switch (field_id) { case 1: this->address = value; @@ -2583,11 +2479,7 @@ bool BluetoothGATTReadDescriptorRequest::decode_varint(uint32_t field_id, uint32 } return true; } -#ifdef USE_API_VARINT64 -bool BluetoothGATTWriteDescriptorRequest::decode_varint(uint32_t field_id, uint64_t value) { -#else -bool BluetoothGATTWriteDescriptorRequest::decode_varint(uint32_t field_id, uint32_t value) { -#endif +bool BluetoothGATTWriteDescriptorRequest::decode_varint(uint32_t field_id, proto_varint_value_t value) { switch (field_id) { case 1: this->address = value; @@ -2612,11 +2504,7 @@ bool BluetoothGATTWriteDescriptorRequest::decode_length(uint32_t field_id, Proto } return true; } -#ifdef USE_API_VARINT64 -bool BluetoothGATTNotifyRequest::decode_varint(uint32_t field_id, uint64_t value) { -#else -bool BluetoothGATTNotifyRequest::decode_varint(uint32_t field_id, uint32_t value) { -#endif +bool BluetoothGATTNotifyRequest::decode_varint(uint32_t field_id, proto_varint_value_t value) { switch (field_id) { case 1: this->address = value; @@ -2744,11 +2632,7 @@ uint32_t BluetoothScannerStateResponse::calculate_size() const { size += ProtoSize::calc_uint32(1, static_cast(this->configured_mode)); return size; } -#ifdef USE_API_VARINT64 -bool BluetoothScannerSetModeRequest::decode_varint(uint32_t field_id, uint64_t value) { -#else -bool BluetoothScannerSetModeRequest::decode_varint(uint32_t field_id, uint32_t value) { -#endif +bool BluetoothScannerSetModeRequest::decode_varint(uint32_t field_id, proto_varint_value_t value) { switch (field_id) { case 1: this->mode = static_cast(value); @@ -2760,11 +2644,7 @@ bool BluetoothScannerSetModeRequest::decode_varint(uint32_t field_id, uint32_t v } #endif #ifdef USE_VOICE_ASSISTANT -#ifdef USE_API_VARINT64 -bool SubscribeVoiceAssistantRequest::decode_varint(uint32_t field_id, uint64_t value) { -#else -bool SubscribeVoiceAssistantRequest::decode_varint(uint32_t field_id, uint32_t value) { -#endif +bool SubscribeVoiceAssistantRequest::decode_varint(uint32_t field_id, proto_varint_value_t value) { switch (field_id) { case 1: this->subscribe = value != 0; @@ -2805,11 +2685,7 @@ uint32_t VoiceAssistantRequest::calculate_size() const { size += ProtoSize::calc_length(1, this->wake_word_phrase.size()); return size; } -#ifdef USE_API_VARINT64 -bool VoiceAssistantResponse::decode_varint(uint32_t field_id, uint64_t value) { -#else -bool VoiceAssistantResponse::decode_varint(uint32_t field_id, uint32_t value) { -#endif +bool VoiceAssistantResponse::decode_varint(uint32_t field_id, proto_varint_value_t value) { switch (field_id) { case 1: this->port = value; @@ -2837,11 +2713,7 @@ bool VoiceAssistantEventData::decode_length(uint32_t field_id, ProtoLengthDelimi } return true; } -#ifdef USE_API_VARINT64 -bool VoiceAssistantEventResponse::decode_varint(uint32_t field_id, uint64_t value) { -#else -bool VoiceAssistantEventResponse::decode_varint(uint32_t field_id, uint32_t value) { -#endif +bool VoiceAssistantEventResponse::decode_varint(uint32_t field_id, proto_varint_value_t value) { switch (field_id) { case 1: this->event_type = static_cast(value); @@ -2862,11 +2734,7 @@ bool VoiceAssistantEventResponse::decode_length(uint32_t field_id, ProtoLengthDe } return true; } -#ifdef USE_API_VARINT64 -bool VoiceAssistantAudio::decode_varint(uint32_t field_id, uint64_t value) { -#else -bool VoiceAssistantAudio::decode_varint(uint32_t field_id, uint32_t value) { -#endif +bool VoiceAssistantAudio::decode_varint(uint32_t field_id, proto_varint_value_t value) { switch (field_id) { case 2: this->end = value != 0; @@ -2898,11 +2766,7 @@ uint32_t VoiceAssistantAudio::calculate_size() const { size += ProtoSize::calc_bool(1, this->end); return size; } -#ifdef USE_API_VARINT64 -bool VoiceAssistantTimerEventResponse::decode_varint(uint32_t field_id, uint64_t value) { -#else -bool VoiceAssistantTimerEventResponse::decode_varint(uint32_t field_id, uint32_t value) { -#endif +bool VoiceAssistantTimerEventResponse::decode_varint(uint32_t field_id, proto_varint_value_t value) { switch (field_id) { case 1: this->event_type = static_cast(value); @@ -2936,11 +2800,7 @@ bool VoiceAssistantTimerEventResponse::decode_length(uint32_t field_id, ProtoLen } return true; } -#ifdef USE_API_VARINT64 -bool VoiceAssistantAnnounceRequest::decode_varint(uint32_t field_id, uint64_t value) { -#else -bool VoiceAssistantAnnounceRequest::decode_varint(uint32_t field_id, uint32_t value) { -#endif +bool VoiceAssistantAnnounceRequest::decode_varint(uint32_t field_id, proto_varint_value_t value) { switch (field_id) { case 4: this->start_conversation = value != 0; @@ -2993,11 +2853,7 @@ uint32_t VoiceAssistantWakeWord::calculate_size() const { } return size; } -#ifdef USE_API_VARINT64 -bool VoiceAssistantExternalWakeWord::decode_varint(uint32_t field_id, uint64_t value) { -#else -bool VoiceAssistantExternalWakeWord::decode_varint(uint32_t field_id, uint32_t value) { -#endif +bool VoiceAssistantExternalWakeWord::decode_varint(uint32_t field_id, proto_varint_value_t value) { switch (field_id) { case 5: this->model_size = value; @@ -3134,11 +2990,7 @@ uint32_t AlarmControlPanelStateResponse::calculate_size() const { #endif return size; } -#ifdef USE_API_VARINT64 -bool AlarmControlPanelCommandRequest::decode_varint(uint32_t field_id, uint64_t value) { -#else -bool AlarmControlPanelCommandRequest::decode_varint(uint32_t field_id, uint32_t value) { -#endif +bool AlarmControlPanelCommandRequest::decode_varint(uint32_t field_id, proto_varint_value_t value) { switch (field_id) { case 2: this->command = static_cast(value); @@ -3230,11 +3082,7 @@ uint32_t TextStateResponse::calculate_size() const { #endif return size; } -#ifdef USE_API_VARINT64 -bool TextCommandRequest::decode_varint(uint32_t field_id, uint64_t value) { -#else -bool TextCommandRequest::decode_varint(uint32_t field_id, uint32_t value) { -#endif +bool TextCommandRequest::decode_varint(uint32_t field_id, proto_varint_value_t value) { switch (field_id) { #ifdef USE_DEVICES case 3: @@ -3319,11 +3167,7 @@ uint32_t DateStateResponse::calculate_size() const { #endif return size; } -#ifdef USE_API_VARINT64 -bool DateCommandRequest::decode_varint(uint32_t field_id, uint64_t value) { -#else -bool DateCommandRequest::decode_varint(uint32_t field_id, uint32_t value) { -#endif +bool DateCommandRequest::decode_varint(uint32_t field_id, proto_varint_value_t value) { switch (field_id) { case 2: this->year = value; @@ -3406,11 +3250,7 @@ uint32_t TimeStateResponse::calculate_size() const { #endif return size; } -#ifdef USE_API_VARINT64 -bool TimeCommandRequest::decode_varint(uint32_t field_id, uint64_t value) { -#else -bool TimeCommandRequest::decode_varint(uint32_t field_id, uint32_t value) { -#endif +bool TimeCommandRequest::decode_varint(uint32_t field_id, proto_varint_value_t value) { switch (field_id) { case 2: this->hour = value; @@ -3553,11 +3393,7 @@ uint32_t ValveStateResponse::calculate_size() const { #endif return size; } -#ifdef USE_API_VARINT64 -bool ValveCommandRequest::decode_varint(uint32_t field_id, uint64_t value) { -#else -bool ValveCommandRequest::decode_varint(uint32_t field_id, uint32_t value) { -#endif +bool ValveCommandRequest::decode_varint(uint32_t field_id, proto_varint_value_t value) { switch (field_id) { case 2: this->has_position = value != 0; @@ -3636,11 +3472,7 @@ uint32_t DateTimeStateResponse::calculate_size() const { #endif return size; } -#ifdef USE_API_VARINT64 -bool DateTimeCommandRequest::decode_varint(uint32_t field_id, uint64_t value) { -#else -bool DateTimeCommandRequest::decode_varint(uint32_t field_id, uint32_t value) { -#endif +bool DateTimeCommandRequest::decode_varint(uint32_t field_id, proto_varint_value_t value) { switch (field_id) { #ifdef USE_DEVICES case 3: @@ -3729,11 +3561,7 @@ uint32_t UpdateStateResponse::calculate_size() const { #endif return size; } -#ifdef USE_API_VARINT64 -bool UpdateCommandRequest::decode_varint(uint32_t field_id, uint64_t value) { -#else -bool UpdateCommandRequest::decode_varint(uint32_t field_id, uint32_t value) { -#endif +bool UpdateCommandRequest::decode_varint(uint32_t field_id, proto_varint_value_t value) { switch (field_id) { case 2: this->command = static_cast(value); @@ -3778,11 +3606,7 @@ uint32_t ZWaveProxyFrame::calculate_size() const { size += ProtoSize::calc_length(1, this->data_len); return size; } -#ifdef USE_API_VARINT64 -bool ZWaveProxyRequest::decode_varint(uint32_t field_id, uint64_t value) { -#else -bool ZWaveProxyRequest::decode_varint(uint32_t field_id, uint32_t value) { -#endif +bool ZWaveProxyRequest::decode_varint(uint32_t field_id, proto_varint_value_t value) { switch (field_id) { case 1: this->type = static_cast(value); @@ -3848,11 +3672,7 @@ uint32_t ListEntitiesInfraredResponse::calculate_size() const { } #endif #ifdef USE_IR_RF -#ifdef USE_API_VARINT64 -bool InfraredRFTransmitRawTimingsRequest::decode_varint(uint32_t field_id, uint64_t value) { -#else -bool InfraredRFTransmitRawTimingsRequest::decode_varint(uint32_t field_id, uint32_t value) { -#endif +bool InfraredRFTransmitRawTimingsRequest::decode_varint(uint32_t field_id, proto_varint_value_t value) { switch (field_id) { #ifdef USE_DEVICES case 1: @@ -3917,11 +3737,7 @@ uint32_t InfraredRFReceiveEvent::calculate_size() const { } #endif #ifdef USE_SERIAL_PROXY -#ifdef USE_API_VARINT64 -bool SerialProxyConfigureRequest::decode_varint(uint32_t field_id, uint64_t value) { -#else -bool SerialProxyConfigureRequest::decode_varint(uint32_t field_id, uint32_t value) { -#endif +bool SerialProxyConfigureRequest::decode_varint(uint32_t field_id, proto_varint_value_t value) { switch (field_id) { case 1: this->instance = value; @@ -3956,11 +3772,7 @@ uint32_t SerialProxyDataReceived::calculate_size() const { size += ProtoSize::calc_length(1, this->data_len_); return size; } -#ifdef USE_API_VARINT64 -bool SerialProxyWriteRequest::decode_varint(uint32_t field_id, uint64_t value) { -#else -bool SerialProxyWriteRequest::decode_varint(uint32_t field_id, uint32_t value) { -#endif +bool SerialProxyWriteRequest::decode_varint(uint32_t field_id, proto_varint_value_t value) { switch (field_id) { case 1: this->instance = value; @@ -3982,11 +3794,7 @@ bool SerialProxyWriteRequest::decode_length(uint32_t field_id, ProtoLengthDelimi } return true; } -#ifdef USE_API_VARINT64 -bool SerialProxySetModemPinsRequest::decode_varint(uint32_t field_id, uint64_t value) { -#else -bool SerialProxySetModemPinsRequest::decode_varint(uint32_t field_id, uint32_t value) { -#endif +bool SerialProxySetModemPinsRequest::decode_varint(uint32_t field_id, proto_varint_value_t value) { switch (field_id) { case 1: this->instance = value; @@ -3999,11 +3807,7 @@ bool SerialProxySetModemPinsRequest::decode_varint(uint32_t field_id, uint32_t v } return true; } -#ifdef USE_API_VARINT64 -bool SerialProxyGetModemPinsRequest::decode_varint(uint32_t field_id, uint64_t value) { -#else -bool SerialProxyGetModemPinsRequest::decode_varint(uint32_t field_id, uint32_t value) { -#endif +bool SerialProxyGetModemPinsRequest::decode_varint(uint32_t field_id, proto_varint_value_t value) { switch (field_id) { case 1: this->instance = value; @@ -4023,11 +3827,7 @@ uint32_t SerialProxyGetModemPinsResponse::calculate_size() const { size += ProtoSize::calc_uint32(1, this->line_states); return size; } -#ifdef USE_API_VARINT64 -bool SerialProxyRequest::decode_varint(uint32_t field_id, uint64_t value) { -#else -bool SerialProxyRequest::decode_varint(uint32_t field_id, uint32_t value) { -#endif +bool SerialProxyRequest::decode_varint(uint32_t field_id, proto_varint_value_t value) { switch (field_id) { case 1: this->instance = value; @@ -4056,11 +3856,7 @@ uint32_t SerialProxyRequestResponse::calculate_size() const { } #endif #ifdef USE_BLUETOOTH_PROXY -#ifdef USE_API_VARINT64 -bool BluetoothSetConnectionParamsRequest::decode_varint(uint32_t field_id, uint64_t value) { -#else -bool BluetoothSetConnectionParamsRequest::decode_varint(uint32_t field_id, uint32_t value) { -#endif +bool BluetoothSetConnectionParamsRequest::decode_varint(uint32_t field_id, proto_varint_value_t value) { switch (field_id) { case 1: this->address = value; diff --git a/esphome/components/api/api_pb2.h b/esphome/components/api/api_pb2.h index de2c0002ae..a4ee0adb8b 100644 --- a/esphome/components/api/api_pb2.h +++ b/esphome/components/api/api_pb2.h @@ -399,11 +399,7 @@ class HelloRequest final : public ProtoDecodableMessage { protected: bool decode_length(uint32_t field_id, ProtoLengthDelimited value) override; -#ifdef USE_API_VARINT64 - bool decode_varint(uint32_t field_id, uint64_t value) override; -#else - bool decode_varint(uint32_t field_id, uint32_t value) override; -#endif + bool decode_varint(uint32_t field_id, proto_varint_value_t value) override; }; class HelloResponse final : public ProtoMessage { public: @@ -692,11 +688,7 @@ class CoverCommandRequest final : public CommandProtoMessage { protected: bool decode_32bit(uint32_t field_id, Proto32Bit value) override; -#ifdef USE_API_VARINT64 - bool decode_varint(uint32_t field_id, uint64_t value) override; -#else - bool decode_varint(uint32_t field_id, uint32_t value) override; -#endif + bool decode_varint(uint32_t field_id, proto_varint_value_t value) override; }; #endif #ifdef USE_FAN @@ -764,11 +756,7 @@ class FanCommandRequest final : public CommandProtoMessage { protected: bool decode_32bit(uint32_t field_id, Proto32Bit value) override; bool decode_length(uint32_t field_id, ProtoLengthDelimited value) override; -#ifdef USE_API_VARINT64 - bool decode_varint(uint32_t field_id, uint64_t value) override; -#else - bool decode_varint(uint32_t field_id, uint32_t value) override; -#endif + bool decode_varint(uint32_t field_id, proto_varint_value_t value) override; }; #endif #ifdef USE_LIGHT @@ -858,11 +846,7 @@ class LightCommandRequest final : public CommandProtoMessage { protected: bool decode_32bit(uint32_t field_id, Proto32Bit value) override; bool decode_length(uint32_t field_id, ProtoLengthDelimited value) override; -#ifdef USE_API_VARINT64 - bool decode_varint(uint32_t field_id, uint64_t value) override; -#else - bool decode_varint(uint32_t field_id, uint32_t value) override; -#endif + bool decode_varint(uint32_t field_id, proto_varint_value_t value) override; }; #endif #ifdef USE_SENSOR @@ -952,11 +936,7 @@ class SwitchCommandRequest final : public CommandProtoMessage { protected: bool decode_32bit(uint32_t field_id, Proto32Bit value) override; -#ifdef USE_API_VARINT64 - bool decode_varint(uint32_t field_id, uint64_t value) override; -#else - bool decode_varint(uint32_t field_id, uint32_t value) override; -#endif + bool decode_varint(uint32_t field_id, proto_varint_value_t value) override; }; #endif #ifdef USE_TEXT_SENSOR @@ -1008,11 +988,7 @@ class SubscribeLogsRequest final : public ProtoDecodableMessage { #endif protected: -#ifdef USE_API_VARINT64 - bool decode_varint(uint32_t field_id, uint64_t value) override; -#else - bool decode_varint(uint32_t field_id, uint32_t value) override; -#endif + bool decode_varint(uint32_t field_id, proto_varint_value_t value) override; }; class SubscribeLogsResponse final : public ProtoMessage { public: @@ -1134,11 +1110,7 @@ class HomeassistantActionResponse final : public ProtoDecodableMessage { protected: bool decode_length(uint32_t field_id, ProtoLengthDelimited value) override; -#ifdef USE_API_VARINT64 - bool decode_varint(uint32_t field_id, uint64_t value) override; -#else - bool decode_varint(uint32_t field_id, uint32_t value) override; -#endif + bool decode_varint(uint32_t field_id, proto_varint_value_t value) override; }; #endif #ifdef USE_API_HOMEASSISTANT_STATES @@ -1204,11 +1176,7 @@ class DSTRule final : public ProtoDecodableMessage { #endif protected: -#ifdef USE_API_VARINT64 - bool decode_varint(uint32_t field_id, uint64_t value) override; -#else - bool decode_varint(uint32_t field_id, uint32_t value) override; -#endif + bool decode_varint(uint32_t field_id, proto_varint_value_t value) override; }; class ParsedTimezone final : public ProtoDecodableMessage { public: @@ -1222,11 +1190,7 @@ class ParsedTimezone final : public ProtoDecodableMessage { protected: bool decode_length(uint32_t field_id, ProtoLengthDelimited value) override; -#ifdef USE_API_VARINT64 - bool decode_varint(uint32_t field_id, uint64_t value) override; -#else - bool decode_varint(uint32_t field_id, uint32_t value) override; -#endif + bool decode_varint(uint32_t field_id, proto_varint_value_t value) override; }; class GetTimeResponse final : public ProtoDecodableMessage { public: @@ -1297,11 +1261,7 @@ class ExecuteServiceArgument final : public ProtoDecodableMessage { protected: bool decode_32bit(uint32_t field_id, Proto32Bit value) override; bool decode_length(uint32_t field_id, ProtoLengthDelimited value) override; -#ifdef USE_API_VARINT64 - bool decode_varint(uint32_t field_id, uint64_t value) override; -#else - bool decode_varint(uint32_t field_id, uint32_t value) override; -#endif + bool decode_varint(uint32_t field_id, proto_varint_value_t value) override; }; class ExecuteServiceRequest final : public ProtoDecodableMessage { public: @@ -1326,11 +1286,7 @@ class ExecuteServiceRequest final : public ProtoDecodableMessage { protected: bool decode_32bit(uint32_t field_id, Proto32Bit value) override; bool decode_length(uint32_t field_id, ProtoLengthDelimited value) override; -#ifdef USE_API_VARINT64 - bool decode_varint(uint32_t field_id, uint64_t value) override; -#else - bool decode_varint(uint32_t field_id, uint32_t value) override; -#endif + bool decode_varint(uint32_t field_id, proto_varint_value_t value) override; }; #endif #ifdef USE_API_USER_DEFINED_ACTION_RESPONSES @@ -1409,11 +1365,7 @@ class CameraImageRequest final : public ProtoDecodableMessage { #endif protected: -#ifdef USE_API_VARINT64 - bool decode_varint(uint32_t field_id, uint64_t value) override; -#else - bool decode_varint(uint32_t field_id, uint32_t value) override; -#endif + bool decode_varint(uint32_t field_id, proto_varint_value_t value) override; }; #endif #ifdef USE_CLIMATE @@ -1512,11 +1464,7 @@ class ClimateCommandRequest final : public CommandProtoMessage { protected: bool decode_32bit(uint32_t field_id, Proto32Bit value) override; bool decode_length(uint32_t field_id, ProtoLengthDelimited value) override; -#ifdef USE_API_VARINT64 - bool decode_varint(uint32_t field_id, uint64_t value) override; -#else - bool decode_varint(uint32_t field_id, uint32_t value) override; -#endif + bool decode_varint(uint32_t field_id, proto_varint_value_t value) override; }; #endif #ifdef USE_WATER_HEATER @@ -1580,11 +1528,7 @@ class WaterHeaterCommandRequest final : public CommandProtoMessage { protected: bool decode_32bit(uint32_t field_id, Proto32Bit value) override; -#ifdef USE_API_VARINT64 - bool decode_varint(uint32_t field_id, uint64_t value) override; -#else - bool decode_varint(uint32_t field_id, uint32_t value) override; -#endif + bool decode_varint(uint32_t field_id, proto_varint_value_t value) override; }; #endif #ifdef USE_NUMBER @@ -1640,11 +1584,7 @@ class NumberCommandRequest final : public CommandProtoMessage { protected: bool decode_32bit(uint32_t field_id, Proto32Bit value) override; -#ifdef USE_API_VARINT64 - bool decode_varint(uint32_t field_id, uint64_t value) override; -#else - bool decode_varint(uint32_t field_id, uint32_t value) override; -#endif + bool decode_varint(uint32_t field_id, proto_varint_value_t value) override; }; #endif #ifdef USE_SELECT @@ -1696,11 +1636,7 @@ class SelectCommandRequest final : public CommandProtoMessage { protected: bool decode_32bit(uint32_t field_id, Proto32Bit value) override; bool decode_length(uint32_t field_id, ProtoLengthDelimited value) override; -#ifdef USE_API_VARINT64 - bool decode_varint(uint32_t field_id, uint64_t value) override; -#else - bool decode_varint(uint32_t field_id, uint32_t value) override; -#endif + bool decode_varint(uint32_t field_id, proto_varint_value_t value) override; }; #endif #ifdef USE_SIREN @@ -1760,11 +1696,7 @@ class SirenCommandRequest final : public CommandProtoMessage { protected: bool decode_32bit(uint32_t field_id, Proto32Bit value) override; bool decode_length(uint32_t field_id, ProtoLengthDelimited value) override; -#ifdef USE_API_VARINT64 - bool decode_varint(uint32_t field_id, uint64_t value) override; -#else - bool decode_varint(uint32_t field_id, uint32_t value) override; -#endif + bool decode_varint(uint32_t field_id, proto_varint_value_t value) override; }; #endif #ifdef USE_LOCK @@ -1820,11 +1752,7 @@ class LockCommandRequest final : public CommandProtoMessage { protected: bool decode_32bit(uint32_t field_id, Proto32Bit value) override; bool decode_length(uint32_t field_id, ProtoLengthDelimited value) override; -#ifdef USE_API_VARINT64 - bool decode_varint(uint32_t field_id, uint64_t value) override; -#else - bool decode_varint(uint32_t field_id, uint32_t value) override; -#endif + bool decode_varint(uint32_t field_id, proto_varint_value_t value) override; }; #endif #ifdef USE_BUTTON @@ -1857,11 +1785,7 @@ class ButtonCommandRequest final : public CommandProtoMessage { protected: bool decode_32bit(uint32_t field_id, Proto32Bit value) override; -#ifdef USE_API_VARINT64 - bool decode_varint(uint32_t field_id, uint64_t value) override; -#else - bool decode_varint(uint32_t field_id, uint32_t value) override; -#endif + bool decode_varint(uint32_t field_id, proto_varint_value_t value) override; }; #endif #ifdef USE_MEDIA_PLAYER @@ -1938,11 +1862,7 @@ class MediaPlayerCommandRequest final : public CommandProtoMessage { protected: bool decode_32bit(uint32_t field_id, Proto32Bit value) override; bool decode_length(uint32_t field_id, ProtoLengthDelimited value) override; -#ifdef USE_API_VARINT64 - bool decode_varint(uint32_t field_id, uint64_t value) override; -#else - bool decode_varint(uint32_t field_id, uint32_t value) override; -#endif + bool decode_varint(uint32_t field_id, proto_varint_value_t value) override; }; #endif #ifdef USE_BLUETOOTH_PROXY @@ -1959,11 +1879,7 @@ class SubscribeBluetoothLEAdvertisementsRequest final : public ProtoDecodableMes #endif protected: -#ifdef USE_API_VARINT64 - bool decode_varint(uint32_t field_id, uint64_t value) override; -#else - bool decode_varint(uint32_t field_id, uint32_t value) override; -#endif + bool decode_varint(uint32_t field_id, proto_varint_value_t value) override; }; class BluetoothLERawAdvertisement final : public ProtoMessage { public: @@ -2013,11 +1929,7 @@ class BluetoothDeviceRequest final : public ProtoDecodableMessage { #endif protected: -#ifdef USE_API_VARINT64 - bool decode_varint(uint32_t field_id, uint64_t value) override; -#else - bool decode_varint(uint32_t field_id, uint32_t value) override; -#endif + bool decode_varint(uint32_t field_id, proto_varint_value_t value) override; }; class BluetoothDeviceConnectionResponse final : public ProtoMessage { public: @@ -2051,11 +1963,7 @@ class BluetoothGATTGetServicesRequest final : public ProtoDecodableMessage { #endif protected: -#ifdef USE_API_VARINT64 - bool decode_varint(uint32_t field_id, uint64_t value) override; -#else - bool decode_varint(uint32_t field_id, uint32_t value) override; -#endif + bool decode_varint(uint32_t field_id, proto_varint_value_t value) override; }; class BluetoothGATTDescriptor final : public ProtoMessage { public: @@ -2146,11 +2054,7 @@ class BluetoothGATTReadRequest final : public ProtoDecodableMessage { #endif protected: -#ifdef USE_API_VARINT64 - bool decode_varint(uint32_t field_id, uint64_t value) override; -#else - bool decode_varint(uint32_t field_id, uint32_t value) override; -#endif + bool decode_varint(uint32_t field_id, proto_varint_value_t value) override; }; class BluetoothGATTReadResponse final : public ProtoMessage { public: @@ -2193,11 +2097,7 @@ class BluetoothGATTWriteRequest final : public ProtoDecodableMessage { protected: bool decode_length(uint32_t field_id, ProtoLengthDelimited value) override; -#ifdef USE_API_VARINT64 - bool decode_varint(uint32_t field_id, uint64_t value) override; -#else - bool decode_varint(uint32_t field_id, uint32_t value) override; -#endif + bool decode_varint(uint32_t field_id, proto_varint_value_t value) override; }; class BluetoothGATTReadDescriptorRequest final : public ProtoDecodableMessage { public: @@ -2213,11 +2113,7 @@ class BluetoothGATTReadDescriptorRequest final : public ProtoDecodableMessage { #endif protected: -#ifdef USE_API_VARINT64 - bool decode_varint(uint32_t field_id, uint64_t value) override; -#else - bool decode_varint(uint32_t field_id, uint32_t value) override; -#endif + bool decode_varint(uint32_t field_id, proto_varint_value_t value) override; }; class BluetoothGATTWriteDescriptorRequest final : public ProtoDecodableMessage { public: @@ -2236,11 +2132,7 @@ class BluetoothGATTWriteDescriptorRequest final : public ProtoDecodableMessage { protected: bool decode_length(uint32_t field_id, ProtoLengthDelimited value) override; -#ifdef USE_API_VARINT64 - bool decode_varint(uint32_t field_id, uint64_t value) override; -#else - bool decode_varint(uint32_t field_id, uint32_t value) override; -#endif + bool decode_varint(uint32_t field_id, proto_varint_value_t value) override; }; class BluetoothGATTNotifyRequest final : public ProtoDecodableMessage { public: @@ -2257,11 +2149,7 @@ class BluetoothGATTNotifyRequest final : public ProtoDecodableMessage { #endif protected: -#ifdef USE_API_VARINT64 - bool decode_varint(uint32_t field_id, uint64_t value) override; -#else - bool decode_varint(uint32_t field_id, uint32_t value) override; -#endif + bool decode_varint(uint32_t field_id, proto_varint_value_t value) override; }; class BluetoothGATTNotifyDataResponse final : public ProtoMessage { public: @@ -2441,11 +2329,7 @@ class BluetoothScannerSetModeRequest final : public ProtoDecodableMessage { #endif protected: -#ifdef USE_API_VARINT64 - bool decode_varint(uint32_t field_id, uint64_t value) override; -#else - bool decode_varint(uint32_t field_id, uint32_t value) override; -#endif + bool decode_varint(uint32_t field_id, proto_varint_value_t value) override; }; #endif #ifdef USE_VOICE_ASSISTANT @@ -2463,11 +2347,7 @@ class SubscribeVoiceAssistantRequest final : public ProtoDecodableMessage { #endif protected: -#ifdef USE_API_VARINT64 - bool decode_varint(uint32_t field_id, uint64_t value) override; -#else - bool decode_varint(uint32_t field_id, uint32_t value) override; -#endif + bool decode_varint(uint32_t field_id, proto_varint_value_t value) override; }; class VoiceAssistantAudioSettings final : public ProtoMessage { public: @@ -2516,11 +2396,7 @@ class VoiceAssistantResponse final : public ProtoDecodableMessage { #endif protected: -#ifdef USE_API_VARINT64 - bool decode_varint(uint32_t field_id, uint64_t value) override; -#else - bool decode_varint(uint32_t field_id, uint32_t value) override; -#endif + bool decode_varint(uint32_t field_id, proto_varint_value_t value) override; }; class VoiceAssistantEventData final : public ProtoDecodableMessage { public: @@ -2548,11 +2424,7 @@ class VoiceAssistantEventResponse final : public ProtoDecodableMessage { protected: bool decode_length(uint32_t field_id, ProtoLengthDelimited value) override; -#ifdef USE_API_VARINT64 - bool decode_varint(uint32_t field_id, uint64_t value) override; -#else - bool decode_varint(uint32_t field_id, uint32_t value) override; -#endif + bool decode_varint(uint32_t field_id, proto_varint_value_t value) override; }; class VoiceAssistantAudio final : public ProtoDecodableMessage { public: @@ -2572,11 +2444,7 @@ class VoiceAssistantAudio final : public ProtoDecodableMessage { protected: bool decode_length(uint32_t field_id, ProtoLengthDelimited value) override; -#ifdef USE_API_VARINT64 - bool decode_varint(uint32_t field_id, uint64_t value) override; -#else - bool decode_varint(uint32_t field_id, uint32_t value) override; -#endif + bool decode_varint(uint32_t field_id, proto_varint_value_t value) override; }; class VoiceAssistantTimerEventResponse final : public ProtoDecodableMessage { public: @@ -2597,11 +2465,7 @@ class VoiceAssistantTimerEventResponse final : public ProtoDecodableMessage { protected: bool decode_length(uint32_t field_id, ProtoLengthDelimited value) override; -#ifdef USE_API_VARINT64 - bool decode_varint(uint32_t field_id, uint64_t value) override; -#else - bool decode_varint(uint32_t field_id, uint32_t value) override; -#endif + bool decode_varint(uint32_t field_id, proto_varint_value_t value) override; }; class VoiceAssistantAnnounceRequest final : public ProtoDecodableMessage { public: @@ -2620,11 +2484,7 @@ class VoiceAssistantAnnounceRequest final : public ProtoDecodableMessage { protected: bool decode_length(uint32_t field_id, ProtoLengthDelimited value) override; -#ifdef USE_API_VARINT64 - bool decode_varint(uint32_t field_id, uint64_t value) override; -#else - bool decode_varint(uint32_t field_id, uint32_t value) override; -#endif + bool decode_varint(uint32_t field_id, proto_varint_value_t value) override; }; class VoiceAssistantAnnounceFinished final : public ProtoMessage { public: @@ -2670,11 +2530,7 @@ class VoiceAssistantExternalWakeWord final : public ProtoDecodableMessage { protected: bool decode_length(uint32_t field_id, ProtoLengthDelimited value) override; -#ifdef USE_API_VARINT64 - bool decode_varint(uint32_t field_id, uint64_t value) override; -#else - bool decode_varint(uint32_t field_id, uint32_t value) override; -#endif + bool decode_varint(uint32_t field_id, proto_varint_value_t value) override; }; class VoiceAssistantConfigurationRequest final : public ProtoDecodableMessage { public: @@ -2776,11 +2632,7 @@ class AlarmControlPanelCommandRequest final : public CommandProtoMessage { protected: bool decode_32bit(uint32_t field_id, Proto32Bit value) override; bool decode_length(uint32_t field_id, ProtoLengthDelimited value) override; -#ifdef USE_API_VARINT64 - bool decode_varint(uint32_t field_id, uint64_t value) override; -#else - bool decode_varint(uint32_t field_id, uint32_t value) override; -#endif + bool decode_varint(uint32_t field_id, proto_varint_value_t value) override; }; #endif #ifdef USE_TEXT @@ -2835,11 +2687,7 @@ class TextCommandRequest final : public CommandProtoMessage { protected: bool decode_32bit(uint32_t field_id, Proto32Bit value) override; bool decode_length(uint32_t field_id, ProtoLengthDelimited value) override; -#ifdef USE_API_VARINT64 - bool decode_varint(uint32_t field_id, uint64_t value) override; -#else - bool decode_varint(uint32_t field_id, uint32_t value) override; -#endif + bool decode_varint(uint32_t field_id, proto_varint_value_t value) override; }; #endif #ifdef USE_DATETIME_DATE @@ -2893,11 +2741,7 @@ class DateCommandRequest final : public CommandProtoMessage { protected: bool decode_32bit(uint32_t field_id, Proto32Bit value) override; -#ifdef USE_API_VARINT64 - bool decode_varint(uint32_t field_id, uint64_t value) override; -#else - bool decode_varint(uint32_t field_id, uint32_t value) override; -#endif + bool decode_varint(uint32_t field_id, proto_varint_value_t value) override; }; #endif #ifdef USE_DATETIME_TIME @@ -2951,11 +2795,7 @@ class TimeCommandRequest final : public CommandProtoMessage { protected: bool decode_32bit(uint32_t field_id, Proto32Bit value) override; -#ifdef USE_API_VARINT64 - bool decode_varint(uint32_t field_id, uint64_t value) override; -#else - bool decode_varint(uint32_t field_id, uint32_t value) override; -#endif + bool decode_varint(uint32_t field_id, proto_varint_value_t value) override; }; #endif #ifdef USE_EVENT @@ -3046,11 +2886,7 @@ class ValveCommandRequest final : public CommandProtoMessage { protected: bool decode_32bit(uint32_t field_id, Proto32Bit value) override; -#ifdef USE_API_VARINT64 - bool decode_varint(uint32_t field_id, uint64_t value) override; -#else - bool decode_varint(uint32_t field_id, uint32_t value) override; -#endif + bool decode_varint(uint32_t field_id, proto_varint_value_t value) override; }; #endif #ifdef USE_DATETIME_DATETIME @@ -3100,11 +2936,7 @@ class DateTimeCommandRequest final : public CommandProtoMessage { protected: bool decode_32bit(uint32_t field_id, Proto32Bit value) override; -#ifdef USE_API_VARINT64 - bool decode_varint(uint32_t field_id, uint64_t value) override; -#else - bool decode_varint(uint32_t field_id, uint32_t value) override; -#endif + bool decode_varint(uint32_t field_id, proto_varint_value_t value) override; }; #endif #ifdef USE_UPDATE @@ -3162,11 +2994,7 @@ class UpdateCommandRequest final : public CommandProtoMessage { protected: bool decode_32bit(uint32_t field_id, Proto32Bit value) override; -#ifdef USE_API_VARINT64 - bool decode_varint(uint32_t field_id, uint64_t value) override; -#else - bool decode_varint(uint32_t field_id, uint32_t value) override; -#endif + bool decode_varint(uint32_t field_id, proto_varint_value_t value) override; }; #endif #ifdef USE_ZWAVE_PROXY @@ -3206,11 +3034,7 @@ class ZWaveProxyRequest final : public ProtoDecodableMessage { protected: bool decode_length(uint32_t field_id, ProtoLengthDelimited value) override; -#ifdef USE_API_VARINT64 - bool decode_varint(uint32_t field_id, uint64_t value) override; -#else - bool decode_varint(uint32_t field_id, uint32_t value) override; -#endif + bool decode_varint(uint32_t field_id, proto_varint_value_t value) override; }; #endif #ifdef USE_INFRARED @@ -3255,11 +3079,7 @@ class InfraredRFTransmitRawTimingsRequest final : public ProtoDecodableMessage { protected: bool decode_32bit(uint32_t field_id, Proto32Bit value) override; bool decode_length(uint32_t field_id, ProtoLengthDelimited value) override; -#ifdef USE_API_VARINT64 - bool decode_varint(uint32_t field_id, uint64_t value) override; -#else - bool decode_varint(uint32_t field_id, uint32_t value) override; -#endif + bool decode_varint(uint32_t field_id, proto_varint_value_t value) override; }; class InfraredRFReceiveEvent final : public ProtoMessage { public: @@ -3301,11 +3121,7 @@ class SerialProxyConfigureRequest final : public ProtoDecodableMessage { #endif protected: -#ifdef USE_API_VARINT64 - bool decode_varint(uint32_t field_id, uint64_t value) override; -#else - bool decode_varint(uint32_t field_id, uint32_t value) override; -#endif + bool decode_varint(uint32_t field_id, proto_varint_value_t value) override; }; class SerialProxyDataReceived final : public ProtoMessage { public: @@ -3345,11 +3161,7 @@ class SerialProxyWriteRequest final : public ProtoDecodableMessage { protected: bool decode_length(uint32_t field_id, ProtoLengthDelimited value) override; -#ifdef USE_API_VARINT64 - bool decode_varint(uint32_t field_id, uint64_t value) override; -#else - bool decode_varint(uint32_t field_id, uint32_t value) override; -#endif + bool decode_varint(uint32_t field_id, proto_varint_value_t value) override; }; class SerialProxySetModemPinsRequest final : public ProtoDecodableMessage { public: @@ -3365,11 +3177,7 @@ class SerialProxySetModemPinsRequest final : public ProtoDecodableMessage { #endif protected: -#ifdef USE_API_VARINT64 - bool decode_varint(uint32_t field_id, uint64_t value) override; -#else - bool decode_varint(uint32_t field_id, uint32_t value) override; -#endif + bool decode_varint(uint32_t field_id, proto_varint_value_t value) override; }; class SerialProxyGetModemPinsRequest final : public ProtoDecodableMessage { public: @@ -3384,11 +3192,7 @@ class SerialProxyGetModemPinsRequest final : public ProtoDecodableMessage { #endif protected: -#ifdef USE_API_VARINT64 - bool decode_varint(uint32_t field_id, uint64_t value) override; -#else - bool decode_varint(uint32_t field_id, uint32_t value) override; -#endif + bool decode_varint(uint32_t field_id, proto_varint_value_t value) override; }; class SerialProxyGetModemPinsResponse final : public ProtoMessage { public: @@ -3421,11 +3225,7 @@ class SerialProxyRequest final : public ProtoDecodableMessage { #endif protected: -#ifdef USE_API_VARINT64 - bool decode_varint(uint32_t field_id, uint64_t value) override; -#else - bool decode_varint(uint32_t field_id, uint32_t value) override; -#endif + bool decode_varint(uint32_t field_id, proto_varint_value_t value) override; }; class SerialProxyRequestResponse final : public ProtoMessage { public: @@ -3465,11 +3265,7 @@ class BluetoothSetConnectionParamsRequest final : public ProtoDecodableMessage { #endif protected: -#ifdef USE_API_VARINT64 - bool decode_varint(uint32_t field_id, uint64_t value) override; -#else - bool decode_varint(uint32_t field_id, uint32_t value) override; -#endif + bool decode_varint(uint32_t field_id, proto_varint_value_t value) override; }; class BluetoothSetConnectionParamsResponse final : public ProtoMessage { public: diff --git a/esphome/components/api/proto.cpp b/esphome/components/api/proto.cpp index e03cc69348..ac13a9a5ab 100644 --- a/esphome/components/api/proto.cpp +++ b/esphome/components/api/proto.cpp @@ -227,11 +227,7 @@ void ProtoDecodableMessage::decode(const uint8_t *buffer, size_t length) { ESP_LOGV(TAG, "Invalid VarInt at offset %ld", (long) (ptr - buffer)); return; } -#ifdef USE_API_VARINT64 - if (!this->decode_varint(field_id, res.as_uint64())) { -#else - if (!this->decode_varint(field_id, res.as_uint32())) { -#endif + if (!this->decode_varint(field_id, res.value)) { ESP_LOGV(TAG, "Cannot decode VarInt field %" PRIu32 " with value %" PRIu32 "!", field_id, res.as_uint32()); } ptr += res.consumed; diff --git a/esphome/components/api/proto.h b/esphome/components/api/proto.h index 7da4dc9bdc..e00bc60971 100644 --- a/esphome/components/api/proto.h +++ b/esphome/components/api/proto.h @@ -98,17 +98,20 @@ inline void encode_varint_to_buffer(uint32_t val, uint8_t *buffer) { * within the same function scope where temporaries are created. */ +/// Type used for decoded varint values - uint64_t when BLE needs 64-bit addresses, uint32_t otherwise +#ifdef USE_API_VARINT64 +using proto_varint_value_t = uint64_t; +#else +using proto_varint_value_t = uint32_t; +#endif + /// Sentinel value for consumed field indicating parse failure inline constexpr uint32_t PROTO_VARINT_PARSE_FAILED = 0; /// Result of parsing a varint: value + number of bytes consumed. /// consumed == PROTO_VARINT_PARSE_FAILED indicates parse failure (not enough data or invalid). struct ProtoVarIntResult { -#ifdef USE_API_VARINT64 - uint64_t value; -#else - uint32_t value; -#endif + proto_varint_value_t value; uint32_t consumed; // PROTO_VARINT_PARSE_FAILED = parse failed constexpr bool has_value() const { return this->consumed != PROTO_VARINT_PARSE_FAILED; } @@ -506,11 +509,7 @@ class ProtoDecodableMessage : public ProtoMessage { protected: ~ProtoDecodableMessage() = default; -#ifdef USE_API_VARINT64 - virtual bool decode_varint(uint32_t field_id, uint64_t value) { return false; } -#else - virtual bool decode_varint(uint32_t field_id, uint32_t value) { return false; } -#endif + virtual bool decode_varint(uint32_t field_id, proto_varint_value_t value) { return false; } virtual bool decode_length(uint32_t field_id, ProtoLengthDelimited value) { return false; } virtual bool decode_32bit(uint32_t field_id, Proto32Bit value) { return false; } // NOTE: decode_64bit removed - wire type 1 not supported diff --git a/script/api_protobuf/api_protobuf.py b/script/api_protobuf/api_protobuf.py index 2febe2580e..e7fdbfd896 100755 --- a/script/api_protobuf/api_protobuf.py +++ b/script/api_protobuf/api_protobuf.py @@ -2213,12 +2213,7 @@ def build_message_type( cpp = "" if decode_varint: - # Use conditional parameter type to match base class - o = "#ifdef USE_API_VARINT64\n" - o += f"bool {desc.name}::decode_varint(uint32_t field_id, uint64_t value) {{\n" - o += "#else\n" - o += f"bool {desc.name}::decode_varint(uint32_t field_id, uint32_t value) {{\n" - o += "#endif\n" + o = f"bool {desc.name}::decode_varint(uint32_t field_id, proto_varint_value_t value) {{\n" o += " switch (field_id) {\n" o += indent("\n".join(decode_varint), " ") + "\n" o += " default: return false;\n" @@ -2226,15 +2221,8 @@ def build_message_type( o += " return true;\n" o += "}\n" cpp += o - prot_lines = [ - "#ifdef USE_API_VARINT64", - "bool decode_varint(uint32_t field_id, uint64_t value) override;", - "#else", - "bool decode_varint(uint32_t field_id, uint32_t value) override;", - "#endif", - ] - for i, line in enumerate(prot_lines): - protected_content.insert(i, line) + prot = "bool decode_varint(uint32_t field_id, proto_varint_value_t value) override;" + protected_content.insert(0, prot) if decode_length: o = f"bool {desc.name}::decode_length(uint32_t field_id, ProtoLengthDelimited value) {{\n" o += " switch (field_id) {\n" From a9ad0cc3f3855aa3eb59d7542828e0a426166908 Mon Sep 17 00:00:00 2001 From: "J. Nick Koston" Date: Sun, 8 Mar 2026 18:58:54 -1000 Subject: [PATCH 12/15] [api] Remove unused ProtoVarInt instance members and ProtoVarIntResult accessors After moving decode_varint to raw proto_varint_value_t, the type- conversion accessors (as_bool, as_int32, as_sint32, as_uint64, etc.) on ProtoVarIntResult are dead code. ProtoVarInt itself is now only used as a static method container for parse(), so remove its constructors, instance accessors, and value_ member. Co-Authored-By: Claude Opus 4.6 --- esphome/components/api/proto.h | 44 +--------------------------------- 1 file changed, 1 insertion(+), 43 deletions(-) diff --git a/esphome/components/api/proto.h b/esphome/components/api/proto.h index e00bc60971..7915b58b57 100644 --- a/esphome/components/api/proto.h +++ b/esphome/components/api/proto.h @@ -117,22 +117,11 @@ struct ProtoVarIntResult { constexpr bool has_value() const { return this->consumed != PROTO_VARINT_PARSE_FAILED; } constexpr uint16_t as_uint16() const { return this->value; } constexpr uint32_t as_uint32() const { return this->value; } - constexpr bool as_bool() const { return this->value; } - constexpr int32_t as_int32() const { return static_cast(this->value); } - constexpr int32_t as_sint32() const { return decode_zigzag32(static_cast(this->value)); } -#ifdef USE_API_VARINT64 - constexpr uint64_t as_uint64() const { return this->value; } - constexpr int64_t as_int64() const { return static_cast(this->value); } - constexpr int64_t as_sint64() const { return decode_zigzag64(this->value); } -#endif }; -/// Representation of a VarInt - in ProtoBuf should be 64bit but we only use 32bit +/// Static varint parsing methods for the protobuf wire format. class ProtoVarInt { public: - ProtoVarInt() : value_(0) {} - explicit ProtoVarInt(uint64_t value) : value_(value) {} - /// Parse a varint from buffer. Caller must ensure len >= 1. /// Returns result with consumed=0 on failure (truncated multi-byte varint). static inline ProtoVarIntResult ESPHOME_ALWAYS_INLINE parse_non_empty(const uint8_t *buffer, uint32_t len) { @@ -162,37 +151,6 @@ class ProtoVarInt { /// Continue parsing varint bytes 4-9 with 64-bit arithmetic. static ProtoVarIntResult parse_wide(const uint8_t *buffer, uint32_t len, uint32_t result32) __attribute__((noinline)); #endif - - public: - constexpr uint16_t as_uint16() const { return this->value_; } - constexpr uint32_t as_uint32() const { return this->value_; } - constexpr bool as_bool() const { return this->value_; } - constexpr int32_t as_int32() const { - // Not ZigZag encoded - return static_cast(this->value_); - } - constexpr int32_t as_sint32() const { - // with ZigZag encoding - return decode_zigzag32(static_cast(this->value_)); - } -#ifdef USE_API_VARINT64 - constexpr uint64_t as_uint64() const { return this->value_; } - constexpr int64_t as_int64() const { - // Not ZigZag encoded - return static_cast(this->value_); - } - constexpr int64_t as_sint64() const { - // with ZigZag encoding - return decode_zigzag64(this->value_); - } -#endif - - protected: -#ifdef USE_API_VARINT64 - uint64_t value_; -#else - uint32_t value_; -#endif }; // Forward declarations for decode_to_message and related encoding helpers From ce70c955c41aa02d072f6ecc4060127a1854517e Mon Sep 17 00:00:00 2001 From: "J. Nick Koston" Date: Sun, 8 Mar 2026 19:52:03 -1000 Subject: [PATCH 13/15] [api] Remove as_uint16/as_uint32 accessors from ProtoVarIntResult, use .value directly Address code review feedback: - Remove as_uint16() and as_uint32() accessors from ProtoVarIntResult - Use .value directly with static_cast where narrowing is needed - Fix ESP_LOGV truncation: use PRIu64 with static_cast for BLE builds Co-Authored-By: Claude Opus 4.6 --- .../components/api/api_frame_helper_plaintext.cpp | 13 ++++++------- esphome/components/api/proto.cpp | 11 ++++++----- esphome/components/api/proto.h | 2 -- 3 files changed, 12 insertions(+), 14 deletions(-) diff --git a/esphome/components/api/api_frame_helper_plaintext.cpp b/esphome/components/api/api_frame_helper_plaintext.cpp index 2fd9196579..1335ae5e60 100644 --- a/esphome/components/api/api_frame_helper_plaintext.cpp +++ b/esphome/components/api/api_frame_helper_plaintext.cpp @@ -136,13 +136,12 @@ APIError APIPlaintextFrameHelper::try_read_frame_() { continue; } - if (msg_size_varint.as_uint32() > MAX_MESSAGE_SIZE) { + if (msg_size_varint.value > MAX_MESSAGE_SIZE) { state_ = State::FAILED; - HELPER_LOG("Bad packet: message size %" PRIu32 " exceeds maximum %u", msg_size_varint.as_uint32(), - MAX_MESSAGE_SIZE); + HELPER_LOG("Bad packet: message size %" PRIu32 " exceeds maximum %u", msg_size_varint.value, MAX_MESSAGE_SIZE); return APIError::BAD_DATA_PACKET; } - rx_header_parsed_len_ = msg_size_varint.as_uint16(); + rx_header_parsed_len_ = static_cast(msg_size_varint.value); // Move to next varint position varint_pos += msg_size_varint.consumed; @@ -152,13 +151,13 @@ APIError APIPlaintextFrameHelper::try_read_frame_() { // not enough data there yet continue; } - if (msg_type_varint.as_uint32() > std::numeric_limits::max()) { + if (msg_type_varint.value > std::numeric_limits::max()) { state_ = State::FAILED; - HELPER_LOG("Bad packet: message type %" PRIu32 " exceeds maximum %u", msg_type_varint.as_uint32(), + HELPER_LOG("Bad packet: message type %" PRIu32 " exceeds maximum %u", msg_type_varint.value, std::numeric_limits::max()); return APIError::BAD_DATA_PACKET; } - rx_header_parsed_type_ = msg_type_varint.as_uint16(); + rx_header_parsed_type_ = static_cast(msg_type_varint.value); rx_header_parsed_ = true; } // header reading done diff --git a/esphome/components/api/proto.cpp b/esphome/components/api/proto.cpp index ac13a9a5ab..e35565dd6d 100644 --- a/esphome/components/api/proto.cpp +++ b/esphome/components/api/proto.cpp @@ -69,7 +69,7 @@ uint32_t ProtoDecodableMessage::count_repeated_field(const uint8_t *buffer, size break; // Invalid data, stop counting } - uint32_t tag = res.as_uint32(); + uint32_t tag = res.value; uint32_t field_type = tag & WIRE_TYPE_MASK; uint32_t field_id = tag >> 3; ptr += res.consumed; @@ -94,7 +94,7 @@ uint32_t ProtoDecodableMessage::count_repeated_field(const uint8_t *buffer, size if (!res.has_value()) { return count; } - uint32_t field_length = res.as_uint32(); + uint32_t field_length = res.value; ptr += res.consumed; if (field_length > static_cast(end - ptr)) { return count; // Out of bounds @@ -215,7 +215,7 @@ void ProtoDecodableMessage::decode(const uint8_t *buffer, size_t length) { return; } - uint32_t tag = res.as_uint32(); + uint32_t tag = res.value; uint32_t field_type = tag & WIRE_TYPE_MASK; uint32_t field_id = tag >> 3; ptr += res.consumed; @@ -228,7 +228,8 @@ void ProtoDecodableMessage::decode(const uint8_t *buffer, size_t length) { return; } if (!this->decode_varint(field_id, res.value)) { - ESP_LOGV(TAG, "Cannot decode VarInt field %" PRIu32 " with value %" PRIu32 "!", field_id, res.as_uint32()); + ESP_LOGV(TAG, "Cannot decode VarInt field %" PRIu32 " with value %" PRIu64 "!", field_id, + static_cast(res.value)); } ptr += res.consumed; break; @@ -239,7 +240,7 @@ void ProtoDecodableMessage::decode(const uint8_t *buffer, size_t length) { ESP_LOGV(TAG, "Invalid Length Delimited at offset %ld", (long) (ptr - buffer)); return; } - uint32_t field_length = res.as_uint32(); + uint32_t field_length = res.value; ptr += res.consumed; if (field_length > static_cast(end - ptr)) { ESP_LOGV(TAG, "Out-of-bounds Length Delimited at offset %ld", (long) (ptr - buffer)); diff --git a/esphome/components/api/proto.h b/esphome/components/api/proto.h index 7915b58b57..7050efb446 100644 --- a/esphome/components/api/proto.h +++ b/esphome/components/api/proto.h @@ -115,8 +115,6 @@ struct ProtoVarIntResult { uint32_t consumed; // PROTO_VARINT_PARSE_FAILED = parse failed constexpr bool has_value() const { return this->consumed != PROTO_VARINT_PARSE_FAILED; } - constexpr uint16_t as_uint16() const { return this->value; } - constexpr uint32_t as_uint32() const { return this->value; } }; /// Static varint parsing methods for the protobuf wire format. From 9f57c2a9b6b31d27440959009bc4f85eceefe95e Mon Sep 17 00:00:00 2001 From: "J. Nick Koston" Date: Sun, 8 Mar 2026 20:52:26 -1000 Subject: [PATCH 14/15] [api] Fix HELPER_LOG format mismatch and remove unused is_varint64 codegen field - Cast msg_size/type_varint.value to uint32_t in HELPER_LOG to match PRIu32 format (proto_varint_value_t is uint64_t on BLE builds) - Remove unused is_varint64 field from api_protobuf.py TypeInfo classes Co-Authored-By: Claude Opus 4.6 --- esphome/components/api/api_frame_helper_plaintext.cpp | 7 ++++--- script/api_protobuf/api_protobuf.py | 8 -------- 2 files changed, 4 insertions(+), 11 deletions(-) diff --git a/esphome/components/api/api_frame_helper_plaintext.cpp b/esphome/components/api/api_frame_helper_plaintext.cpp index 1335ae5e60..793cece3b8 100644 --- a/esphome/components/api/api_frame_helper_plaintext.cpp +++ b/esphome/components/api/api_frame_helper_plaintext.cpp @@ -138,7 +138,8 @@ APIError APIPlaintextFrameHelper::try_read_frame_() { if (msg_size_varint.value > MAX_MESSAGE_SIZE) { state_ = State::FAILED; - HELPER_LOG("Bad packet: message size %" PRIu32 " exceeds maximum %u", msg_size_varint.value, MAX_MESSAGE_SIZE); + HELPER_LOG("Bad packet: message size %" PRIu32 " exceeds maximum %u", + static_cast(msg_size_varint.value), MAX_MESSAGE_SIZE); return APIError::BAD_DATA_PACKET; } rx_header_parsed_len_ = static_cast(msg_size_varint.value); @@ -153,8 +154,8 @@ APIError APIPlaintextFrameHelper::try_read_frame_() { } if (msg_type_varint.value > std::numeric_limits::max()) { state_ = State::FAILED; - HELPER_LOG("Bad packet: message type %" PRIu32 " exceeds maximum %u", msg_type_varint.value, - std::numeric_limits::max()); + HELPER_LOG("Bad packet: message type %" PRIu32 " exceeds maximum %u", + static_cast(msg_type_varint.value), std::numeric_limits::max()); return APIError::BAD_DATA_PACKET; } rx_header_parsed_type_ = static_cast(msg_type_varint.value); diff --git a/script/api_protobuf/api_protobuf.py b/script/api_protobuf/api_protobuf.py index e7fdbfd896..1c2a3e5cc2 100755 --- a/script/api_protobuf/api_protobuf.py +++ b/script/api_protobuf/api_protobuf.py @@ -193,7 +193,6 @@ class TypeInfo(ABC): return f"case {self.number}: this->{self.field_name} = {content}; break;" decode_varint = None - is_varint64 = False @property def decode_length_content(self) -> str: @@ -463,7 +462,6 @@ class Int64Type(TypeInfo): cpp_type = "int64_t" default_value = "0" decode_varint = "static_cast(value)" - is_varint64 = True encode_func = "encode_int64" wire_type = WireType.VARINT # Uses wire type 0 @@ -484,7 +482,6 @@ class UInt64Type(TypeInfo): cpp_type = "uint64_t" default_value = "0" decode_varint = "value" - is_varint64 = True encode_func = "encode_uint64" wire_type = WireType.VARINT # Uses wire type 0 @@ -1286,7 +1283,6 @@ class SInt64Type(TypeInfo): cpp_type = "int64_t" default_value = "0" decode_varint = "decode_zigzag64(value)" - is_varint64 = True encode_func = "encode_sint64" wire_type = WireType.VARINT # Uses wire type 0 @@ -1624,10 +1620,6 @@ class RepeatedTypeInfo(TypeInfo): """ return self._ti.wire_type - @property - def is_varint64(self): - return self._ti.is_varint64 - @property def decode_varint_content(self) -> str: # Pointer fields don't support decoding From 5dbf35051a969cec0d9d1e23a39d23b8942038b6 Mon Sep 17 00:00:00 2001 From: "J. Nick Koston" Date: Sun, 8 Mar 2026 20:58:13 -1000 Subject: [PATCH 15/15] [api] Add explicit static_cast for tag/field_length narrowing MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Consistency with frame helper code — makes the uint64→uint32 narrowing explicit on BLE builds where proto_varint_value_t is uint64_t. Co-Authored-By: Claude Opus 4.6 --- esphome/components/api/proto.cpp | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/esphome/components/api/proto.cpp b/esphome/components/api/proto.cpp index e35565dd6d..8959ac7a2a 100644 --- a/esphome/components/api/proto.cpp +++ b/esphome/components/api/proto.cpp @@ -69,7 +69,7 @@ uint32_t ProtoDecodableMessage::count_repeated_field(const uint8_t *buffer, size break; // Invalid data, stop counting } - uint32_t tag = res.value; + uint32_t tag = static_cast(res.value); uint32_t field_type = tag & WIRE_TYPE_MASK; uint32_t field_id = tag >> 3; ptr += res.consumed; @@ -94,7 +94,7 @@ uint32_t ProtoDecodableMessage::count_repeated_field(const uint8_t *buffer, size if (!res.has_value()) { return count; } - uint32_t field_length = res.value; + uint32_t field_length = static_cast(res.value); ptr += res.consumed; if (field_length > static_cast(end - ptr)) { return count; // Out of bounds @@ -215,7 +215,7 @@ void ProtoDecodableMessage::decode(const uint8_t *buffer, size_t length) { return; } - uint32_t tag = res.value; + uint32_t tag = static_cast(res.value); uint32_t field_type = tag & WIRE_TYPE_MASK; uint32_t field_id = tag >> 3; ptr += res.consumed; @@ -240,7 +240,7 @@ void ProtoDecodableMessage::decode(const uint8_t *buffer, size_t length) { ESP_LOGV(TAG, "Invalid Length Delimited at offset %ld", (long) (ptr - buffer)); return; } - uint32_t field_length = res.value; + uint32_t field_length = static_cast(res.value); ptr += res.consumed; if (field_length > static_cast(end - ptr)) { ESP_LOGV(TAG, "Out-of-bounds Length Delimited at offset %ld", (long) (ptr - buffer));