mirror of
https://github.com/esphome/esphome.git
synced 2026-09-01 02:26:01 +00:00
[api] Inline ProtoVarInt::parse fast path and return consumed in struct
Replace optional<ProtoVarInt> + 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.
This commit is contained in:
@@ -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<uint16_t>::max()) {
|
||||
if (msg_type_varint.as_uint32() > std::numeric_limits<uint16_t>::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<uint16_t>::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
|
||||
|
||||
@@ -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<enums::LogLevel>(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<uint32_t>(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<enums::LockCommand>(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<uint32_t>(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<enums::BluetoothScannerMode>(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<enums::VoiceAssistantEvent>(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<enums::VoiceAssistantTimerEvent>(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<enums::AlarmControlPanelStateCommand>(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<enums::UpdateCommand>(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<enums::ZWaveProxyRequestType>(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();
|
||||
|
||||
@@ -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:
|
||||
|
||||
@@ -20,20 +20,40 @@ void ProtoWriteBuffer::encode_varint_raw_slow_(uint32_t value) {
|
||||
*this->pos_++ = static_cast<uint8_t>(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> 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<size_t>(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<size_t>(end - ptr)) {
|
||||
ESP_LOGV(TAG, "Out-of-bounds Length Delimited at offset %ld", (long) (ptr - buffer));
|
||||
return;
|
||||
|
||||
@@ -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<int32_t>(this->value); }
|
||||
constexpr int32_t as_sint32() const { return decode_zigzag32(static_cast<uint32_t>(this->value)); }
|
||||
#ifdef USE_API_VARINT64
|
||||
constexpr uint64_t as_uint64() const { return this->value; }
|
||||
constexpr int64_t as_int64() const { return static_cast<int64_t>(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<ProtoVarInt> 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<ProtoVarInt> 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
|
||||
|
||||
@@ -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"
|
||||
|
||||
Reference in New Issue
Block a user