mirror of
https://github.com/esphome/esphome.git
synced 2026-09-11 15:27:33 +00:00
[api] Trim the decode path: void decode_field, bool from the low word, slow varint out parameter
decode_field() no longer returns a bool that only fed a verbose log; unknown fields are skipped silently like every other protobuf decoder does, and each message loses the return value materialisation. Bools read the low 32 bits of the varint, which drops the second compare on 64 bit varint builds. The multi byte varint path writes its value through an out parameter instead of returning a 16 byte struct, which takes the spills out of the decode loop and count_repeated_field.
This commit is contained in:
+181
-240
File diff suppressed because it is too large
Load Diff
@@ -424,7 +424,7 @@ class HelloRequest final : public ProtoDecodableMessage {
|
||||
#endif
|
||||
|
||||
protected:
|
||||
bool decode_field(uint32_t tag, const uint8_t *data, proto_varint_value_t scalar) override;
|
||||
void decode_field(uint32_t tag, const uint8_t *data, proto_varint_value_t scalar) override;
|
||||
};
|
||||
class HelloResponse final : public ProtoMessage {
|
||||
public:
|
||||
@@ -468,7 +468,7 @@ class DisconnectRequest final : public ProtoDecodableMessage {
|
||||
#endif
|
||||
|
||||
protected:
|
||||
bool decode_field(uint32_t tag, const uint8_t *data, proto_varint_value_t scalar) override;
|
||||
void decode_field(uint32_t tag, const uint8_t *data, proto_varint_value_t scalar) override;
|
||||
};
|
||||
class DisconnectResponse final : public ProtoMessage {
|
||||
public:
|
||||
@@ -844,7 +844,7 @@ class CoverCommandRequest final : public CommandProtoMessage {
|
||||
#endif
|
||||
|
||||
protected:
|
||||
bool decode_field(uint32_t tag, const uint8_t *data, proto_varint_value_t scalar) override;
|
||||
void decode_field(uint32_t tag, const uint8_t *data, proto_varint_value_t scalar) override;
|
||||
};
|
||||
#endif
|
||||
#ifdef USE_FAN
|
||||
@@ -918,7 +918,7 @@ class FanCommandRequest final : public CommandProtoMessage {
|
||||
#endif
|
||||
|
||||
protected:
|
||||
bool decode_field(uint32_t tag, const uint8_t *data, proto_varint_value_t scalar) override;
|
||||
void decode_field(uint32_t tag, const uint8_t *data, proto_varint_value_t scalar) override;
|
||||
};
|
||||
#endif
|
||||
#ifdef USE_LIGHT
|
||||
@@ -1014,7 +1014,7 @@ class LightCommandRequest final : public CommandProtoMessage {
|
||||
#endif
|
||||
|
||||
protected:
|
||||
bool decode_field(uint32_t tag, const uint8_t *data, proto_varint_value_t scalar) override;
|
||||
void decode_field(uint32_t tag, const uint8_t *data, proto_varint_value_t scalar) override;
|
||||
};
|
||||
#endif
|
||||
#ifdef USE_SENSOR
|
||||
@@ -1119,7 +1119,7 @@ class SwitchCommandRequest final : public CommandProtoMessage {
|
||||
#endif
|
||||
|
||||
protected:
|
||||
bool decode_field(uint32_t tag, const uint8_t *data, proto_varint_value_t scalar) override;
|
||||
void decode_field(uint32_t tag, const uint8_t *data, proto_varint_value_t scalar) override;
|
||||
};
|
||||
#endif
|
||||
#ifdef USE_TEXT_SENSOR
|
||||
@@ -1179,7 +1179,7 @@ class SubscribeLogsRequest final : public ProtoDecodableMessage {
|
||||
#endif
|
||||
|
||||
protected:
|
||||
bool decode_field(uint32_t tag, const uint8_t *data, proto_varint_value_t scalar) override;
|
||||
void decode_field(uint32_t tag, const uint8_t *data, proto_varint_value_t scalar) override;
|
||||
};
|
||||
class SubscribeLogsResponse final : public ProtoMessage {
|
||||
public:
|
||||
@@ -1222,7 +1222,7 @@ class NoiseEncryptionSetKeyRequest final : public ProtoDecodableMessage {
|
||||
#endif
|
||||
|
||||
protected:
|
||||
bool decode_field(uint32_t tag, const uint8_t *data, proto_varint_value_t scalar) override;
|
||||
void decode_field(uint32_t tag, const uint8_t *data, proto_varint_value_t scalar) override;
|
||||
};
|
||||
class NoiseEncryptionSetKeyResponse final : public ProtoMessage {
|
||||
public:
|
||||
@@ -1316,7 +1316,7 @@ class HomeassistantActionResponse final : public ProtoDecodableMessage {
|
||||
#endif
|
||||
|
||||
protected:
|
||||
bool decode_field(uint32_t tag, const uint8_t *data, proto_varint_value_t scalar) override;
|
||||
void decode_field(uint32_t tag, const uint8_t *data, proto_varint_value_t scalar) override;
|
||||
};
|
||||
#endif
|
||||
#ifdef USE_API_HOMEASSISTANT_STATES
|
||||
@@ -1357,7 +1357,7 @@ class HomeAssistantStateResponse final : public ProtoDecodableMessage {
|
||||
#endif
|
||||
|
||||
protected:
|
||||
bool decode_field(uint32_t tag, const uint8_t *data, proto_varint_value_t scalar) override;
|
||||
void decode_field(uint32_t tag, const uint8_t *data, proto_varint_value_t scalar) override;
|
||||
};
|
||||
#endif
|
||||
class GetTimeRequest final : public ProtoMessage {
|
||||
@@ -1386,7 +1386,7 @@ class DSTRule final : public ProtoDecodableMessage {
|
||||
#endif
|
||||
|
||||
protected:
|
||||
bool decode_field(uint32_t tag, const uint8_t *data, proto_varint_value_t scalar) override;
|
||||
void decode_field(uint32_t tag, const uint8_t *data, proto_varint_value_t scalar) override;
|
||||
};
|
||||
class ParsedTimezone final : public ProtoDecodableMessage {
|
||||
public:
|
||||
@@ -1399,7 +1399,7 @@ class ParsedTimezone final : public ProtoDecodableMessage {
|
||||
#endif
|
||||
|
||||
protected:
|
||||
bool decode_field(uint32_t tag, const uint8_t *data, proto_varint_value_t scalar) override;
|
||||
void decode_field(uint32_t tag, const uint8_t *data, proto_varint_value_t scalar) override;
|
||||
};
|
||||
class GetTimeResponse final : public ProtoDecodableMessage {
|
||||
public:
|
||||
@@ -1416,7 +1416,7 @@ class GetTimeResponse final : public ProtoDecodableMessage {
|
||||
#endif
|
||||
|
||||
protected:
|
||||
bool decode_field(uint32_t tag, const uint8_t *data, proto_varint_value_t scalar) override;
|
||||
void decode_field(uint32_t tag, const uint8_t *data, proto_varint_value_t scalar) override;
|
||||
};
|
||||
#ifdef USE_API_USER_DEFINED_ACTIONS
|
||||
class ListEntitiesServicesArgument final : public ProtoMessage {
|
||||
@@ -1484,7 +1484,7 @@ class ExecuteServiceArgument final : public ProtoDecodableMessage {
|
||||
#endif
|
||||
|
||||
protected:
|
||||
bool decode_field(uint32_t tag, const uint8_t *data, proto_varint_value_t scalar) override;
|
||||
void decode_field(uint32_t tag, const uint8_t *data, proto_varint_value_t scalar) override;
|
||||
};
|
||||
class ExecuteServiceRequest final : public ProtoDecodableMessage {
|
||||
public:
|
||||
@@ -1507,7 +1507,7 @@ class ExecuteServiceRequest final : public ProtoDecodableMessage {
|
||||
#endif
|
||||
|
||||
protected:
|
||||
bool decode_field(uint32_t tag, const uint8_t *data, proto_varint_value_t scalar) override;
|
||||
void decode_field(uint32_t tag, const uint8_t *data, proto_varint_value_t scalar) override;
|
||||
};
|
||||
#endif
|
||||
#ifdef USE_API_USER_DEFINED_ACTION_RESPONSES
|
||||
@@ -1598,7 +1598,7 @@ class CameraImageRequest final : public ProtoDecodableMessage {
|
||||
#endif
|
||||
|
||||
protected:
|
||||
bool decode_field(uint32_t tag, const uint8_t *data, proto_varint_value_t scalar) override;
|
||||
void decode_field(uint32_t tag, const uint8_t *data, proto_varint_value_t scalar) override;
|
||||
};
|
||||
#endif
|
||||
#ifdef USE_CLIMATE
|
||||
@@ -1704,7 +1704,7 @@ class ClimateCommandRequest final : public CommandProtoMessage {
|
||||
#endif
|
||||
|
||||
protected:
|
||||
bool decode_field(uint32_t tag, const uint8_t *data, proto_varint_value_t scalar) override;
|
||||
void decode_field(uint32_t tag, const uint8_t *data, proto_varint_value_t scalar) override;
|
||||
};
|
||||
#endif
|
||||
#ifdef USE_WATER_HEATER
|
||||
@@ -1776,7 +1776,7 @@ class WaterHeaterCommandRequest final : public CommandProtoMessage {
|
||||
#endif
|
||||
|
||||
protected:
|
||||
bool decode_field(uint32_t tag, const uint8_t *data, proto_varint_value_t scalar) override;
|
||||
void decode_field(uint32_t tag, const uint8_t *data, proto_varint_value_t scalar) override;
|
||||
};
|
||||
#endif
|
||||
#ifdef USE_NUMBER
|
||||
@@ -1839,7 +1839,7 @@ class NumberCommandRequest final : public CommandProtoMessage {
|
||||
#endif
|
||||
|
||||
protected:
|
||||
bool decode_field(uint32_t tag, const uint8_t *data, proto_varint_value_t scalar) override;
|
||||
void decode_field(uint32_t tag, const uint8_t *data, proto_varint_value_t scalar) override;
|
||||
};
|
||||
#endif
|
||||
#ifdef USE_SELECT
|
||||
@@ -1897,7 +1897,7 @@ class SelectCommandRequest final : public CommandProtoMessage {
|
||||
#endif
|
||||
|
||||
protected:
|
||||
bool decode_field(uint32_t tag, const uint8_t *data, proto_varint_value_t scalar) override;
|
||||
void decode_field(uint32_t tag, const uint8_t *data, proto_varint_value_t scalar) override;
|
||||
};
|
||||
#endif
|
||||
#ifdef USE_SIREN
|
||||
@@ -1963,7 +1963,7 @@ class SirenCommandRequest final : public CommandProtoMessage {
|
||||
#endif
|
||||
|
||||
protected:
|
||||
bool decode_field(uint32_t tag, const uint8_t *data, proto_varint_value_t scalar) override;
|
||||
void decode_field(uint32_t tag, const uint8_t *data, proto_varint_value_t scalar) override;
|
||||
};
|
||||
#endif
|
||||
#ifdef USE_LOCK
|
||||
@@ -2025,7 +2025,7 @@ class LockCommandRequest final : public CommandProtoMessage {
|
||||
#endif
|
||||
|
||||
protected:
|
||||
bool decode_field(uint32_t tag, const uint8_t *data, proto_varint_value_t scalar) override;
|
||||
void decode_field(uint32_t tag, const uint8_t *data, proto_varint_value_t scalar) override;
|
||||
};
|
||||
#endif
|
||||
#ifdef USE_BUTTON
|
||||
@@ -2061,7 +2061,7 @@ class ButtonCommandRequest final : public CommandProtoMessage {
|
||||
#endif
|
||||
|
||||
protected:
|
||||
bool decode_field(uint32_t tag, const uint8_t *data, proto_varint_value_t scalar) override;
|
||||
void decode_field(uint32_t tag, const uint8_t *data, proto_varint_value_t scalar) override;
|
||||
};
|
||||
#endif
|
||||
#ifdef USE_MEDIA_PLAYER
|
||||
@@ -2147,7 +2147,7 @@ class MediaPlayerCommandRequest final : public CommandProtoMessage {
|
||||
#endif
|
||||
|
||||
protected:
|
||||
bool decode_field(uint32_t tag, const uint8_t *data, proto_varint_value_t scalar) override;
|
||||
void decode_field(uint32_t tag, const uint8_t *data, proto_varint_value_t scalar) override;
|
||||
};
|
||||
#endif
|
||||
#ifdef USE_BLUETOOTH_PROXY
|
||||
@@ -2164,7 +2164,7 @@ class SubscribeBluetoothLEAdvertisementsRequest final : public ProtoDecodableMes
|
||||
#endif
|
||||
|
||||
protected:
|
||||
bool decode_field(uint32_t tag, const uint8_t *data, proto_varint_value_t scalar) override;
|
||||
void decode_field(uint32_t tag, const uint8_t *data, proto_varint_value_t scalar) override;
|
||||
};
|
||||
class BluetoothLERawAdvertisement final : public ProtoMessage {
|
||||
public:
|
||||
@@ -2218,7 +2218,7 @@ class BluetoothDeviceRequest final : public ProtoDecodableMessage {
|
||||
#endif
|
||||
|
||||
protected:
|
||||
bool decode_field(uint32_t tag, const uint8_t *data, proto_varint_value_t scalar) override;
|
||||
void decode_field(uint32_t tag, const uint8_t *data, proto_varint_value_t scalar) override;
|
||||
};
|
||||
class BluetoothDeviceConnectionResponse final : public ProtoMessage {
|
||||
public:
|
||||
@@ -2256,7 +2256,7 @@ class BluetoothGATTGetServicesRequest final : public ProtoDecodableMessage {
|
||||
#endif
|
||||
|
||||
protected:
|
||||
bool decode_field(uint32_t tag, const uint8_t *data, proto_varint_value_t scalar) override;
|
||||
void decode_field(uint32_t tag, const uint8_t *data, proto_varint_value_t scalar) override;
|
||||
};
|
||||
class BluetoothGATTDescriptor final : public ProtoMessage {
|
||||
public:
|
||||
@@ -2367,7 +2367,7 @@ class BluetoothGATTReadRequest final : public ProtoDecodableMessage {
|
||||
#endif
|
||||
|
||||
protected:
|
||||
bool decode_field(uint32_t tag, const uint8_t *data, proto_varint_value_t scalar) override;
|
||||
void decode_field(uint32_t tag, const uint8_t *data, proto_varint_value_t scalar) override;
|
||||
};
|
||||
class BluetoothGATTReadResponse final : public ProtoMessage {
|
||||
public:
|
||||
@@ -2413,7 +2413,7 @@ class BluetoothGATTWriteRequest final : public ProtoDecodableMessage {
|
||||
#endif
|
||||
|
||||
protected:
|
||||
bool decode_field(uint32_t tag, const uint8_t *data, proto_varint_value_t scalar) override;
|
||||
void decode_field(uint32_t tag, const uint8_t *data, proto_varint_value_t scalar) override;
|
||||
};
|
||||
class BluetoothGATTReadDescriptorRequest final : public ProtoDecodableMessage {
|
||||
public:
|
||||
@@ -2429,7 +2429,7 @@ class BluetoothGATTReadDescriptorRequest final : public ProtoDecodableMessage {
|
||||
#endif
|
||||
|
||||
protected:
|
||||
bool decode_field(uint32_t tag, const uint8_t *data, proto_varint_value_t scalar) override;
|
||||
void decode_field(uint32_t tag, const uint8_t *data, proto_varint_value_t scalar) override;
|
||||
};
|
||||
class BluetoothGATTWriteDescriptorRequest final : public ProtoDecodableMessage {
|
||||
public:
|
||||
@@ -2447,7 +2447,7 @@ class BluetoothGATTWriteDescriptorRequest final : public ProtoDecodableMessage {
|
||||
#endif
|
||||
|
||||
protected:
|
||||
bool decode_field(uint32_t tag, const uint8_t *data, proto_varint_value_t scalar) override;
|
||||
void decode_field(uint32_t tag, const uint8_t *data, proto_varint_value_t scalar) override;
|
||||
};
|
||||
class BluetoothGATTNotifyRequest final : public ProtoDecodableMessage {
|
||||
public:
|
||||
@@ -2464,7 +2464,7 @@ class BluetoothGATTNotifyRequest final : public ProtoDecodableMessage {
|
||||
#endif
|
||||
|
||||
protected:
|
||||
bool decode_field(uint32_t tag, const uint8_t *data, proto_varint_value_t scalar) override;
|
||||
void decode_field(uint32_t tag, const uint8_t *data, proto_varint_value_t scalar) override;
|
||||
};
|
||||
class BluetoothGATTNotifyDataResponse final : public ProtoMessage {
|
||||
public:
|
||||
@@ -2682,7 +2682,7 @@ class BluetoothScannerSetModeRequest final : public ProtoDecodableMessage {
|
||||
#endif
|
||||
|
||||
protected:
|
||||
bool decode_field(uint32_t tag, const uint8_t *data, proto_varint_value_t scalar) override;
|
||||
void decode_field(uint32_t tag, const uint8_t *data, proto_varint_value_t scalar) override;
|
||||
};
|
||||
#endif
|
||||
#ifdef USE_VOICE_ASSISTANT
|
||||
@@ -2700,7 +2700,7 @@ class SubscribeVoiceAssistantRequest final : public ProtoDecodableMessage {
|
||||
#endif
|
||||
|
||||
protected:
|
||||
bool decode_field(uint32_t tag, const uint8_t *data, proto_varint_value_t scalar) override;
|
||||
void decode_field(uint32_t tag, const uint8_t *data, proto_varint_value_t scalar) override;
|
||||
};
|
||||
class VoiceAssistantAudioSettings final : public ProtoMessage {
|
||||
public:
|
||||
@@ -2757,7 +2757,7 @@ class VoiceAssistantResponse final : public ProtoDecodableMessage {
|
||||
#endif
|
||||
|
||||
protected:
|
||||
bool decode_field(uint32_t tag, const uint8_t *data, proto_varint_value_t scalar) override;
|
||||
void decode_field(uint32_t tag, const uint8_t *data, proto_varint_value_t scalar) override;
|
||||
};
|
||||
class VoiceAssistantEventData final : public ProtoDecodableMessage {
|
||||
public:
|
||||
@@ -2768,7 +2768,7 @@ class VoiceAssistantEventData final : public ProtoDecodableMessage {
|
||||
#endif
|
||||
|
||||
protected:
|
||||
bool decode_field(uint32_t tag, const uint8_t *data, proto_varint_value_t scalar) override;
|
||||
void decode_field(uint32_t tag, const uint8_t *data, proto_varint_value_t scalar) override;
|
||||
};
|
||||
class VoiceAssistantEventResponse final : public ProtoDecodableMessage {
|
||||
public:
|
||||
@@ -2784,7 +2784,7 @@ class VoiceAssistantEventResponse final : public ProtoDecodableMessage {
|
||||
#endif
|
||||
|
||||
protected:
|
||||
bool decode_field(uint32_t tag, const uint8_t *data, proto_varint_value_t scalar) override;
|
||||
void decode_field(uint32_t tag, const uint8_t *data, proto_varint_value_t scalar) override;
|
||||
};
|
||||
class VoiceAssistantAudio final : public ProtoDecodableMessage {
|
||||
public:
|
||||
@@ -2809,7 +2809,7 @@ class VoiceAssistantAudio final : public ProtoDecodableMessage {
|
||||
#endif
|
||||
|
||||
protected:
|
||||
bool decode_field(uint32_t tag, const uint8_t *data, proto_varint_value_t scalar) override;
|
||||
void decode_field(uint32_t tag, const uint8_t *data, proto_varint_value_t scalar) override;
|
||||
};
|
||||
class VoiceAssistantTimerEventResponse final : public ProtoDecodableMessage {
|
||||
public:
|
||||
@@ -2829,7 +2829,7 @@ class VoiceAssistantTimerEventResponse final : public ProtoDecodableMessage {
|
||||
#endif
|
||||
|
||||
protected:
|
||||
bool decode_field(uint32_t tag, const uint8_t *data, proto_varint_value_t scalar) override;
|
||||
void decode_field(uint32_t tag, const uint8_t *data, proto_varint_value_t scalar) override;
|
||||
};
|
||||
class VoiceAssistantAnnounceRequest final : public ProtoDecodableMessage {
|
||||
public:
|
||||
@@ -2847,7 +2847,7 @@ class VoiceAssistantAnnounceRequest final : public ProtoDecodableMessage {
|
||||
#endif
|
||||
|
||||
protected:
|
||||
bool decode_field(uint32_t tag, const uint8_t *data, proto_varint_value_t scalar) override;
|
||||
void decode_field(uint32_t tag, const uint8_t *data, proto_varint_value_t scalar) override;
|
||||
};
|
||||
class VoiceAssistantAnnounceFinished final : public ProtoMessage {
|
||||
public:
|
||||
@@ -2900,7 +2900,7 @@ class VoiceAssistantExternalWakeWord final : public ProtoDecodableMessage {
|
||||
#endif
|
||||
|
||||
protected:
|
||||
bool decode_field(uint32_t tag, const uint8_t *data, proto_varint_value_t scalar) override;
|
||||
void decode_field(uint32_t tag, const uint8_t *data, proto_varint_value_t scalar) override;
|
||||
};
|
||||
class VoiceAssistantConfigurationRequest final : public ProtoDecodableMessage {
|
||||
public:
|
||||
@@ -2915,7 +2915,7 @@ class VoiceAssistantConfigurationRequest final : public ProtoDecodableMessage {
|
||||
#endif
|
||||
|
||||
protected:
|
||||
bool decode_field(uint32_t tag, const uint8_t *data, proto_varint_value_t scalar) override;
|
||||
void decode_field(uint32_t tag, const uint8_t *data, proto_varint_value_t scalar) override;
|
||||
};
|
||||
class VoiceAssistantConfigurationResponse final : public ProtoMessage {
|
||||
public:
|
||||
@@ -2952,7 +2952,7 @@ class VoiceAssistantSetConfiguration final : public ProtoDecodableMessage {
|
||||
#endif
|
||||
|
||||
protected:
|
||||
bool decode_field(uint32_t tag, const uint8_t *data, proto_varint_value_t scalar) override;
|
||||
void decode_field(uint32_t tag, const uint8_t *data, proto_varint_value_t scalar) override;
|
||||
};
|
||||
#endif
|
||||
#ifdef USE_ALARM_CONTROL_PANEL
|
||||
@@ -3012,7 +3012,7 @@ class AlarmControlPanelCommandRequest final : public CommandProtoMessage {
|
||||
#endif
|
||||
|
||||
protected:
|
||||
bool decode_field(uint32_t tag, const uint8_t *data, proto_varint_value_t scalar) override;
|
||||
void decode_field(uint32_t tag, const uint8_t *data, proto_varint_value_t scalar) override;
|
||||
};
|
||||
#endif
|
||||
#ifdef USE_TEXT
|
||||
@@ -3073,7 +3073,7 @@ class TextCommandRequest final : public CommandProtoMessage {
|
||||
#endif
|
||||
|
||||
protected:
|
||||
bool decode_field(uint32_t tag, const uint8_t *data, proto_varint_value_t scalar) override;
|
||||
void decode_field(uint32_t tag, const uint8_t *data, proto_varint_value_t scalar) override;
|
||||
};
|
||||
#endif
|
||||
#ifdef USE_DATETIME_DATE
|
||||
@@ -3134,7 +3134,7 @@ class DateCommandRequest final : public CommandProtoMessage {
|
||||
#endif
|
||||
|
||||
protected:
|
||||
bool decode_field(uint32_t tag, const uint8_t *data, proto_varint_value_t scalar) override;
|
||||
void decode_field(uint32_t tag, const uint8_t *data, proto_varint_value_t scalar) override;
|
||||
};
|
||||
#endif
|
||||
#ifdef USE_DATETIME_TIME
|
||||
@@ -3195,7 +3195,7 @@ class TimeCommandRequest final : public CommandProtoMessage {
|
||||
#endif
|
||||
|
||||
protected:
|
||||
bool decode_field(uint32_t tag, const uint8_t *data, proto_varint_value_t scalar) override;
|
||||
void decode_field(uint32_t tag, const uint8_t *data, proto_varint_value_t scalar) override;
|
||||
};
|
||||
#endif
|
||||
#ifdef USE_EVENT
|
||||
@@ -3301,7 +3301,7 @@ class ValveCommandRequest final : public CommandProtoMessage {
|
||||
#endif
|
||||
|
||||
protected:
|
||||
bool decode_field(uint32_t tag, const uint8_t *data, proto_varint_value_t scalar) override;
|
||||
void decode_field(uint32_t tag, const uint8_t *data, proto_varint_value_t scalar) override;
|
||||
};
|
||||
#endif
|
||||
#ifdef USE_DATETIME_DATETIME
|
||||
@@ -3358,7 +3358,7 @@ class DateTimeCommandRequest final : public CommandProtoMessage {
|
||||
#endif
|
||||
|
||||
protected:
|
||||
bool decode_field(uint32_t tag, const uint8_t *data, proto_varint_value_t scalar) override;
|
||||
void decode_field(uint32_t tag, const uint8_t *data, proto_varint_value_t scalar) override;
|
||||
};
|
||||
#endif
|
||||
#ifdef USE_UPDATE
|
||||
@@ -3423,7 +3423,7 @@ class UpdateCommandRequest final : public CommandProtoMessage {
|
||||
#endif
|
||||
|
||||
protected:
|
||||
bool decode_field(uint32_t tag, const uint8_t *data, proto_varint_value_t scalar) override;
|
||||
void decode_field(uint32_t tag, const uint8_t *data, proto_varint_value_t scalar) override;
|
||||
};
|
||||
#endif
|
||||
#ifdef USE_ZWAVE_PROXY
|
||||
@@ -3447,7 +3447,7 @@ class ZWaveProxyFrame final : public ProtoDecodableMessage {
|
||||
#endif
|
||||
|
||||
protected:
|
||||
bool decode_field(uint32_t tag, const uint8_t *data, proto_varint_value_t scalar) override;
|
||||
void decode_field(uint32_t tag, const uint8_t *data, proto_varint_value_t scalar) override;
|
||||
};
|
||||
class ZWaveProxyRequest final : public ProtoDecodableMessage {
|
||||
public:
|
||||
@@ -3470,7 +3470,7 @@ class ZWaveProxyRequest final : public ProtoDecodableMessage {
|
||||
#endif
|
||||
|
||||
protected:
|
||||
bool decode_field(uint32_t tag, const uint8_t *data, proto_varint_value_t scalar) override;
|
||||
void decode_field(uint32_t tag, const uint8_t *data, proto_varint_value_t scalar) override;
|
||||
};
|
||||
class ZWaveProxyRequestResponse final : public ProtoMessage {
|
||||
public:
|
||||
@@ -3540,7 +3540,7 @@ class InfraredRFTransmitRawTimingsRequest final : public ProtoDecodableMessage {
|
||||
#endif
|
||||
|
||||
protected:
|
||||
bool decode_field(uint32_t tag, const uint8_t *data, proto_varint_value_t scalar) override;
|
||||
void decode_field(uint32_t tag, const uint8_t *data, proto_varint_value_t scalar) override;
|
||||
};
|
||||
class InfraredRFReceiveEvent final : public ProtoMessage {
|
||||
public:
|
||||
@@ -3611,7 +3611,7 @@ class SerialProxyConfigureRequest final : public ProtoDecodableMessage {
|
||||
#endif
|
||||
|
||||
protected:
|
||||
bool decode_field(uint32_t tag, const uint8_t *data, proto_varint_value_t scalar) override;
|
||||
void decode_field(uint32_t tag, const uint8_t *data, proto_varint_value_t scalar) override;
|
||||
};
|
||||
class SerialProxyDataReceived final : public ProtoMessage {
|
||||
public:
|
||||
@@ -3654,7 +3654,7 @@ class SerialProxyWriteRequest final : public ProtoDecodableMessage {
|
||||
#endif
|
||||
|
||||
protected:
|
||||
bool decode_field(uint32_t tag, const uint8_t *data, proto_varint_value_t scalar) override;
|
||||
void decode_field(uint32_t tag, const uint8_t *data, proto_varint_value_t scalar) override;
|
||||
};
|
||||
class SerialProxySetModemPinsRequest final : public ProtoDecodableMessage {
|
||||
public:
|
||||
@@ -3670,7 +3670,7 @@ class SerialProxySetModemPinsRequest final : public ProtoDecodableMessage {
|
||||
#endif
|
||||
|
||||
protected:
|
||||
bool decode_field(uint32_t tag, const uint8_t *data, proto_varint_value_t scalar) override;
|
||||
void decode_field(uint32_t tag, const uint8_t *data, proto_varint_value_t scalar) override;
|
||||
};
|
||||
class SerialProxyGetModemPinsRequest final : public ProtoDecodableMessage {
|
||||
public:
|
||||
@@ -3685,7 +3685,7 @@ class SerialProxyGetModemPinsRequest final : public ProtoDecodableMessage {
|
||||
#endif
|
||||
|
||||
protected:
|
||||
bool decode_field(uint32_t tag, const uint8_t *data, proto_varint_value_t scalar) override;
|
||||
void decode_field(uint32_t tag, const uint8_t *data, proto_varint_value_t scalar) override;
|
||||
};
|
||||
class SerialProxyGetModemPinsResponse final : public ProtoMessage {
|
||||
public:
|
||||
@@ -3723,7 +3723,7 @@ class SerialProxyRequest final : public ProtoDecodableMessage {
|
||||
#endif
|
||||
|
||||
protected:
|
||||
bool decode_field(uint32_t tag, const uint8_t *data, proto_varint_value_t scalar) override;
|
||||
void decode_field(uint32_t tag, const uint8_t *data, proto_varint_value_t scalar) override;
|
||||
};
|
||||
class SerialProxyRequestResponse final : public ProtoMessage {
|
||||
public:
|
||||
@@ -3767,7 +3767,7 @@ class BluetoothSetConnectionParamsRequest final : public ProtoDecodableMessage {
|
||||
#endif
|
||||
|
||||
protected:
|
||||
bool decode_field(uint32_t tag, const uint8_t *data, proto_varint_value_t scalar) override;
|
||||
void decode_field(uint32_t tag, const uint8_t *data, proto_varint_value_t scalar) override;
|
||||
};
|
||||
class BluetoothSetConnectionParamsResponse final : public ProtoMessage {
|
||||
public:
|
||||
|
||||
@@ -20,7 +20,7 @@ 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) {
|
||||
uint32_t ProtoVarInt::parse_slow(const uint8_t *buffer, uint32_t len, proto_varint_value_t &value) {
|
||||
// Multi-byte varint: first byte already checked to have high bit set
|
||||
uint32_t result32 = buffer[0] & 0x7F;
|
||||
#ifdef USE_API_VARINT64
|
||||
@@ -32,28 +32,30 @@ ProtoVarIntResult ProtoVarInt::parse_slow(const uint8_t *buffer, uint32_t len) {
|
||||
uint8_t val = buffer[i];
|
||||
result32 |= uint32_t(val & 0x7F) << (i * 7);
|
||||
if ((val & 0x80) == 0) {
|
||||
return {result32, i + 1};
|
||||
value = result32;
|
||||
return i + 1;
|
||||
}
|
||||
}
|
||||
#ifdef USE_API_VARINT64
|
||||
return parse_wide(buffer, len, result32);
|
||||
return parse_wide(buffer, len, result32, value);
|
||||
#else
|
||||
return {0, PROTO_VARINT_PARSE_FAILED};
|
||||
return PROTO_VARINT_PARSE_FAILED;
|
||||
#endif
|
||||
}
|
||||
|
||||
#ifdef USE_API_VARINT64
|
||||
ProtoVarIntResult ProtoVarInt::parse_wide(const uint8_t *buffer, uint32_t len, uint32_t result32) {
|
||||
uint32_t ProtoVarInt::parse_wide(const uint8_t *buffer, uint32_t len, uint32_t result32, uint64_t &value) {
|
||||
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) {
|
||||
return {result64, i + 1};
|
||||
value = result64;
|
||||
return i + 1;
|
||||
}
|
||||
}
|
||||
return {0, PROTO_VARINT_PARSE_FAILED};
|
||||
return PROTO_VARINT_PARSE_FAILED;
|
||||
}
|
||||
#endif
|
||||
|
||||
@@ -222,11 +224,13 @@ void ProtoDecodableMessage::decode(const uint8_t *buffer, size_t length) {
|
||||
value = *ptr++;
|
||||
return true;
|
||||
}
|
||||
auto res = ProtoVarInt::parse_non_empty(ptr, end - ptr);
|
||||
if (!res.has_value())
|
||||
// Separate out variable so the fast path above keeps `value` in a register
|
||||
proto_varint_value_t wide;
|
||||
uint32_t consumed = ProtoVarInt::parse_slow(ptr, end - ptr, wide);
|
||||
if (consumed == PROTO_VARINT_PARSE_FAILED)
|
||||
return false;
|
||||
value = res.value;
|
||||
ptr += res.consumed;
|
||||
value = wide;
|
||||
ptr += consumed;
|
||||
return true;
|
||||
};
|
||||
|
||||
@@ -281,9 +285,7 @@ void ProtoDecodableMessage::decode(const uint8_t *buffer, size_t length) {
|
||||
return;
|
||||
}
|
||||
}
|
||||
if (!this->decode_field(tag, data, scalar)) {
|
||||
ESP_LOGV(TAG, "Cannot decode field %" PRIu32 " with wire type %" PRIu32 "!", tag >> 3, field_type);
|
||||
}
|
||||
this->decode_field(tag, data, scalar);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -145,7 +145,9 @@ 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);
|
||||
ProtoVarIntResult res;
|
||||
res.consumed = parse_slow(buffer, len, res.value);
|
||||
return res;
|
||||
}
|
||||
|
||||
/// Parse a varint from buffer (safe for empty buffers).
|
||||
@@ -156,13 +158,16 @@ class ProtoVarInt {
|
||||
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));
|
||||
/// Multi-byte varint (first byte has the high bit set), outlined to keep the fast path small.
|
||||
/// Writes the value and returns the bytes consumed, PROTO_VARINT_PARSE_FAILED when truncated.
|
||||
static uint32_t parse_slow(const uint8_t *buffer, uint32_t len, proto_varint_value_t &value)
|
||||
__attribute__((noinline));
|
||||
|
||||
protected:
|
||||
#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 uint32_t parse_wide(const uint8_t *buffer, uint32_t len, uint32_t result32, uint64_t &value)
|
||||
__attribute__((noinline));
|
||||
#endif
|
||||
};
|
||||
|
||||
@@ -181,6 +186,8 @@ class ProtoFieldValue {
|
||||
ProtoFieldValue(const uint8_t *data, proto_varint_value_t scalar) : data_(data), scalar_(scalar) {}
|
||||
|
||||
proto_varint_value_t as_varint() const { return this->scalar_; }
|
||||
// A bool is sent as 0 or 1, so the low word is enough and saves a second compare with 64 bit varints
|
||||
bool as_bool() const { return static_cast<uint32_t>(this->scalar_) != 0; }
|
||||
|
||||
// Length-delimited accessors
|
||||
const uint8_t *data() const { return this->data_; }
|
||||
@@ -730,10 +737,10 @@ class ProtoDecodableMessage : public ProtoMessage {
|
||||
protected:
|
||||
~ProtoDecodableMessage() = default;
|
||||
/// Store one decoded field; \p scalar is the varint or fixed32 value, or the length of the
|
||||
/// length-delimited payload at \p data. Return false for an unknown field or wrong wire type.
|
||||
/// length-delimited payload at \p data. An unknown field or wrong wire type matches no case and is skipped.
|
||||
/// Three register arguments keep the decode loop free of spills.
|
||||
// NOTE: wire type 1 (64-bit fixed) is not supported
|
||||
virtual bool decode_field(uint32_t tag, const uint8_t *data, proto_varint_value_t scalar) { return false; }
|
||||
virtual void decode_field(uint32_t tag, const uint8_t *data, proto_varint_value_t scalar) {}
|
||||
};
|
||||
|
||||
class ProtoSize {
|
||||
|
||||
@@ -804,7 +804,7 @@ class BoolType(VarintTypeMixin, TypeInfo):
|
||||
_varint_max_bits = 1
|
||||
cpp_type = "bool"
|
||||
default_value = "false"
|
||||
decode_expr = "value.as_varint() != 0"
|
||||
decode_expr = "value.as_bool()"
|
||||
encode_func = "encode_bool"
|
||||
wire_type = WireType.VARINT # Uses wire type 0
|
||||
|
||||
@@ -2658,16 +2658,16 @@ def build_message_type(
|
||||
|
||||
cpp = ""
|
||||
if decode:
|
||||
o = f"bool {desc.name}::decode_field(uint32_t tag, const uint8_t *data, proto_varint_value_t scalar) {{\n"
|
||||
o = f"void {desc.name}::decode_field(uint32_t tag, const uint8_t *data, proto_varint_value_t scalar) {{\n"
|
||||
o += " const ProtoFieldValue value(data, scalar);\n"
|
||||
o += " switch (tag) {\n"
|
||||
o += indent("\n".join(decode), " ") + "\n"
|
||||
o += " default: return false;\n"
|
||||
o += " default:\n"
|
||||
o += " break;\n"
|
||||
o += " }\n"
|
||||
o += " return true;\n"
|
||||
o += "}\n"
|
||||
cpp += o
|
||||
prot = "bool decode_field(uint32_t tag, const uint8_t *data, proto_varint_value_t scalar) override;"
|
||||
prot = "void decode_field(uint32_t tag, const uint8_t *data, proto_varint_value_t scalar) override;"
|
||||
protected_content.insert(0, prot)
|
||||
|
||||
# Generate custom decode() override for messages with FixedVector fields
|
||||
|
||||
@@ -199,7 +199,7 @@ def _decode_case(field_type: int, number: int) -> str:
|
||||
("field_type", "number", "wire_type", "accessor"),
|
||||
[
|
||||
(UINT32, 2, "WIRE_TYPE_VARINT", "value.as_varint()"),
|
||||
(BOOL, 3, "WIRE_TYPE_VARINT", "value.as_varint() != 0"),
|
||||
(BOOL, 3, "WIRE_TYPE_VARINT", "value.as_bool()"),
|
||||
(STRING, 1, "WIRE_TYPE_LENGTH_DELIMITED", "value.data()"),
|
||||
(FLOAT, 4, "WIRE_TYPE_FIXED32", "value.as_float()"),
|
||||
(FIXED32, 5, "WIRE_TYPE_FIXED32", "value.as_fixed32()"),
|
||||
@@ -223,12 +223,12 @@ def test_message_gets_a_single_decode_field_override() -> None:
|
||||
desc.field.add(name="count", number=2, type=UINT32)
|
||||
desc.field.add(name="level", number=3, type=FLOAT)
|
||||
header, cpp, _ = build_message_type(desc, {}, {"Mixed": SOURCE_CLIENT})
|
||||
decl = "bool decode_field(uint32_t tag, const uint8_t *data, proto_varint_value_t scalar) override;"
|
||||
decl = "void decode_field(uint32_t tag, const uint8_t *data, proto_varint_value_t scalar) override;"
|
||||
assert header.count(decl) == 1
|
||||
assert "decode_varint" not in header and "decode_length" not in header
|
||||
assert (
|
||||
cpp.count(
|
||||
"bool Mixed::decode_field(uint32_t tag, const uint8_t *data, proto_varint_value_t scalar) {"
|
||||
"void Mixed::decode_field(uint32_t tag, const uint8_t *data, proto_varint_value_t scalar) {"
|
||||
)
|
||||
== 1
|
||||
)
|
||||
|
||||
Reference in New Issue
Block a user