[api] Change decode_varint parameter from ProtoVarIntResult to raw value type

Pass uint32_t (or uint64_t when USE_API_VARINT64 is defined) directly
to decode_varint() instead of the ProtoVarIntResult struct. This
eliminates accessor method overhead in each of the 51 overrides,
replacing value.as_uint32() with direct value usage, value.as_bool()
with value != 0, etc. No vtable growth - single virtual method with
conditionally-typed parameter.

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
This commit is contained in:
J. Nick Koston
2026-03-08 18:39:59 -10:00
co-authored by Claude Opus 4.6
parent f4724d7797
commit fcd72336f0
5 changed files with 715 additions and 281 deletions
File diff suppressed because it is too large Load Diff
+255 -51
View File
@@ -399,7 +399,11 @@ class HelloRequest final : public ProtoDecodableMessage {
protected:
bool decode_length(uint32_t field_id, ProtoLengthDelimited value) override;
bool decode_varint(uint32_t field_id, ProtoVarIntResult value) override;
#ifdef USE_API_VARINT64
bool decode_varint(uint32_t field_id, uint64_t value) override;
#else
bool decode_varint(uint32_t field_id, uint32_t value) override;
#endif
};
class HelloResponse final : public ProtoMessage {
public:
@@ -688,7 +692,11 @@ class CoverCommandRequest final : public CommandProtoMessage {
protected:
bool decode_32bit(uint32_t field_id, Proto32Bit value) override;
bool decode_varint(uint32_t field_id, ProtoVarIntResult value) override;
#ifdef USE_API_VARINT64
bool decode_varint(uint32_t field_id, uint64_t value) override;
#else
bool decode_varint(uint32_t field_id, uint32_t value) override;
#endif
};
#endif
#ifdef USE_FAN
@@ -756,7 +764,11 @@ class FanCommandRequest final : public CommandProtoMessage {
protected:
bool decode_32bit(uint32_t field_id, Proto32Bit value) override;
bool decode_length(uint32_t field_id, ProtoLengthDelimited value) override;
bool decode_varint(uint32_t field_id, ProtoVarIntResult value) override;
#ifdef USE_API_VARINT64
bool decode_varint(uint32_t field_id, uint64_t value) override;
#else
bool decode_varint(uint32_t field_id, uint32_t value) override;
#endif
};
#endif
#ifdef USE_LIGHT
@@ -846,7 +858,11 @@ class LightCommandRequest final : public CommandProtoMessage {
protected:
bool decode_32bit(uint32_t field_id, Proto32Bit value) override;
bool decode_length(uint32_t field_id, ProtoLengthDelimited value) override;
bool decode_varint(uint32_t field_id, ProtoVarIntResult value) override;
#ifdef USE_API_VARINT64
bool decode_varint(uint32_t field_id, uint64_t value) override;
#else
bool decode_varint(uint32_t field_id, uint32_t value) override;
#endif
};
#endif
#ifdef USE_SENSOR
@@ -936,7 +952,11 @@ class SwitchCommandRequest final : public CommandProtoMessage {
protected:
bool decode_32bit(uint32_t field_id, Proto32Bit value) override;
bool decode_varint(uint32_t field_id, ProtoVarIntResult value) override;
#ifdef USE_API_VARINT64
bool decode_varint(uint32_t field_id, uint64_t value) override;
#else
bool decode_varint(uint32_t field_id, uint32_t value) override;
#endif
};
#endif
#ifdef USE_TEXT_SENSOR
@@ -988,7 +1008,11 @@ class SubscribeLogsRequest final : public ProtoDecodableMessage {
#endif
protected:
bool decode_varint(uint32_t field_id, ProtoVarIntResult value) override;
#ifdef USE_API_VARINT64
bool decode_varint(uint32_t field_id, uint64_t value) override;
#else
bool decode_varint(uint32_t field_id, uint32_t value) override;
#endif
};
class SubscribeLogsResponse final : public ProtoMessage {
public:
@@ -1110,7 +1134,11 @@ class HomeassistantActionResponse final : public ProtoDecodableMessage {
protected:
bool decode_length(uint32_t field_id, ProtoLengthDelimited value) override;
bool decode_varint(uint32_t field_id, ProtoVarIntResult value) override;
#ifdef USE_API_VARINT64
bool decode_varint(uint32_t field_id, uint64_t value) override;
#else
bool decode_varint(uint32_t field_id, uint32_t value) override;
#endif
};
#endif
#ifdef USE_API_HOMEASSISTANT_STATES
@@ -1176,7 +1204,11 @@ class DSTRule final : public ProtoDecodableMessage {
#endif
protected:
bool decode_varint(uint32_t field_id, ProtoVarIntResult value) override;
#ifdef USE_API_VARINT64
bool decode_varint(uint32_t field_id, uint64_t value) override;
#else
bool decode_varint(uint32_t field_id, uint32_t value) override;
#endif
};
class ParsedTimezone final : public ProtoDecodableMessage {
public:
@@ -1190,7 +1222,11 @@ class ParsedTimezone final : public ProtoDecodableMessage {
protected:
bool decode_length(uint32_t field_id, ProtoLengthDelimited value) override;
bool decode_varint(uint32_t field_id, ProtoVarIntResult value) override;
#ifdef USE_API_VARINT64
bool decode_varint(uint32_t field_id, uint64_t value) override;
#else
bool decode_varint(uint32_t field_id, uint32_t value) override;
#endif
};
class GetTimeResponse final : public ProtoDecodableMessage {
public:
@@ -1261,7 +1297,11 @@ class ExecuteServiceArgument final : public ProtoDecodableMessage {
protected:
bool decode_32bit(uint32_t field_id, Proto32Bit value) override;
bool decode_length(uint32_t field_id, ProtoLengthDelimited value) override;
bool decode_varint(uint32_t field_id, ProtoVarIntResult value) override;
#ifdef USE_API_VARINT64
bool decode_varint(uint32_t field_id, uint64_t value) override;
#else
bool decode_varint(uint32_t field_id, uint32_t value) override;
#endif
};
class ExecuteServiceRequest final : public ProtoDecodableMessage {
public:
@@ -1286,7 +1326,11 @@ class ExecuteServiceRequest final : public ProtoDecodableMessage {
protected:
bool decode_32bit(uint32_t field_id, Proto32Bit value) override;
bool decode_length(uint32_t field_id, ProtoLengthDelimited value) override;
bool decode_varint(uint32_t field_id, ProtoVarIntResult value) override;
#ifdef USE_API_VARINT64
bool decode_varint(uint32_t field_id, uint64_t value) override;
#else
bool decode_varint(uint32_t field_id, uint32_t value) override;
#endif
};
#endif
#ifdef USE_API_USER_DEFINED_ACTION_RESPONSES
@@ -1365,7 +1409,11 @@ class CameraImageRequest final : public ProtoDecodableMessage {
#endif
protected:
bool decode_varint(uint32_t field_id, ProtoVarIntResult value) override;
#ifdef USE_API_VARINT64
bool decode_varint(uint32_t field_id, uint64_t value) override;
#else
bool decode_varint(uint32_t field_id, uint32_t value) override;
#endif
};
#endif
#ifdef USE_CLIMATE
@@ -1464,7 +1512,11 @@ class ClimateCommandRequest final : public CommandProtoMessage {
protected:
bool decode_32bit(uint32_t field_id, Proto32Bit value) override;
bool decode_length(uint32_t field_id, ProtoLengthDelimited value) override;
bool decode_varint(uint32_t field_id, ProtoVarIntResult value) override;
#ifdef USE_API_VARINT64
bool decode_varint(uint32_t field_id, uint64_t value) override;
#else
bool decode_varint(uint32_t field_id, uint32_t value) override;
#endif
};
#endif
#ifdef USE_WATER_HEATER
@@ -1528,7 +1580,11 @@ class WaterHeaterCommandRequest final : public CommandProtoMessage {
protected:
bool decode_32bit(uint32_t field_id, Proto32Bit value) override;
bool decode_varint(uint32_t field_id, ProtoVarIntResult value) override;
#ifdef USE_API_VARINT64
bool decode_varint(uint32_t field_id, uint64_t value) override;
#else
bool decode_varint(uint32_t field_id, uint32_t value) override;
#endif
};
#endif
#ifdef USE_NUMBER
@@ -1584,7 +1640,11 @@ class NumberCommandRequest final : public CommandProtoMessage {
protected:
bool decode_32bit(uint32_t field_id, Proto32Bit value) override;
bool decode_varint(uint32_t field_id, ProtoVarIntResult value) override;
#ifdef USE_API_VARINT64
bool decode_varint(uint32_t field_id, uint64_t value) override;
#else
bool decode_varint(uint32_t field_id, uint32_t value) override;
#endif
};
#endif
#ifdef USE_SELECT
@@ -1636,7 +1696,11 @@ class SelectCommandRequest final : public CommandProtoMessage {
protected:
bool decode_32bit(uint32_t field_id, Proto32Bit value) override;
bool decode_length(uint32_t field_id, ProtoLengthDelimited value) override;
bool decode_varint(uint32_t field_id, ProtoVarIntResult value) override;
#ifdef USE_API_VARINT64
bool decode_varint(uint32_t field_id, uint64_t value) override;
#else
bool decode_varint(uint32_t field_id, uint32_t value) override;
#endif
};
#endif
#ifdef USE_SIREN
@@ -1696,7 +1760,11 @@ class SirenCommandRequest final : public CommandProtoMessage {
protected:
bool decode_32bit(uint32_t field_id, Proto32Bit value) override;
bool decode_length(uint32_t field_id, ProtoLengthDelimited value) override;
bool decode_varint(uint32_t field_id, ProtoVarIntResult value) override;
#ifdef USE_API_VARINT64
bool decode_varint(uint32_t field_id, uint64_t value) override;
#else
bool decode_varint(uint32_t field_id, uint32_t value) override;
#endif
};
#endif
#ifdef USE_LOCK
@@ -1752,7 +1820,11 @@ class LockCommandRequest final : public CommandProtoMessage {
protected:
bool decode_32bit(uint32_t field_id, Proto32Bit value) override;
bool decode_length(uint32_t field_id, ProtoLengthDelimited value) override;
bool decode_varint(uint32_t field_id, ProtoVarIntResult value) override;
#ifdef USE_API_VARINT64
bool decode_varint(uint32_t field_id, uint64_t value) override;
#else
bool decode_varint(uint32_t field_id, uint32_t value) override;
#endif
};
#endif
#ifdef USE_BUTTON
@@ -1785,7 +1857,11 @@ class ButtonCommandRequest final : public CommandProtoMessage {
protected:
bool decode_32bit(uint32_t field_id, Proto32Bit value) override;
bool decode_varint(uint32_t field_id, ProtoVarIntResult value) override;
#ifdef USE_API_VARINT64
bool decode_varint(uint32_t field_id, uint64_t value) override;
#else
bool decode_varint(uint32_t field_id, uint32_t value) override;
#endif
};
#endif
#ifdef USE_MEDIA_PLAYER
@@ -1862,7 +1938,11 @@ class MediaPlayerCommandRequest final : public CommandProtoMessage {
protected:
bool decode_32bit(uint32_t field_id, Proto32Bit value) override;
bool decode_length(uint32_t field_id, ProtoLengthDelimited value) override;
bool decode_varint(uint32_t field_id, ProtoVarIntResult value) override;
#ifdef USE_API_VARINT64
bool decode_varint(uint32_t field_id, uint64_t value) override;
#else
bool decode_varint(uint32_t field_id, uint32_t value) override;
#endif
};
#endif
#ifdef USE_BLUETOOTH_PROXY
@@ -1879,7 +1959,11 @@ class SubscribeBluetoothLEAdvertisementsRequest final : public ProtoDecodableMes
#endif
protected:
bool decode_varint(uint32_t field_id, ProtoVarIntResult value) override;
#ifdef USE_API_VARINT64
bool decode_varint(uint32_t field_id, uint64_t value) override;
#else
bool decode_varint(uint32_t field_id, uint32_t value) override;
#endif
};
class BluetoothLERawAdvertisement final : public ProtoMessage {
public:
@@ -1929,7 +2013,11 @@ class BluetoothDeviceRequest final : public ProtoDecodableMessage {
#endif
protected:
bool decode_varint(uint32_t field_id, ProtoVarIntResult value) override;
#ifdef USE_API_VARINT64
bool decode_varint(uint32_t field_id, uint64_t value) override;
#else
bool decode_varint(uint32_t field_id, uint32_t value) override;
#endif
};
class BluetoothDeviceConnectionResponse final : public ProtoMessage {
public:
@@ -1963,7 +2051,11 @@ class BluetoothGATTGetServicesRequest final : public ProtoDecodableMessage {
#endif
protected:
bool decode_varint(uint32_t field_id, ProtoVarIntResult value) override;
#ifdef USE_API_VARINT64
bool decode_varint(uint32_t field_id, uint64_t value) override;
#else
bool decode_varint(uint32_t field_id, uint32_t value) override;
#endif
};
class BluetoothGATTDescriptor final : public ProtoMessage {
public:
@@ -2054,7 +2146,11 @@ class BluetoothGATTReadRequest final : public ProtoDecodableMessage {
#endif
protected:
bool decode_varint(uint32_t field_id, ProtoVarIntResult value) override;
#ifdef USE_API_VARINT64
bool decode_varint(uint32_t field_id, uint64_t value) override;
#else
bool decode_varint(uint32_t field_id, uint32_t value) override;
#endif
};
class BluetoothGATTReadResponse final : public ProtoMessage {
public:
@@ -2097,7 +2193,11 @@ class BluetoothGATTWriteRequest final : public ProtoDecodableMessage {
protected:
bool decode_length(uint32_t field_id, ProtoLengthDelimited value) override;
bool decode_varint(uint32_t field_id, ProtoVarIntResult value) override;
#ifdef USE_API_VARINT64
bool decode_varint(uint32_t field_id, uint64_t value) override;
#else
bool decode_varint(uint32_t field_id, uint32_t value) override;
#endif
};
class BluetoothGATTReadDescriptorRequest final : public ProtoDecodableMessage {
public:
@@ -2113,7 +2213,11 @@ class BluetoothGATTReadDescriptorRequest final : public ProtoDecodableMessage {
#endif
protected:
bool decode_varint(uint32_t field_id, ProtoVarIntResult value) override;
#ifdef USE_API_VARINT64
bool decode_varint(uint32_t field_id, uint64_t value) override;
#else
bool decode_varint(uint32_t field_id, uint32_t value) override;
#endif
};
class BluetoothGATTWriteDescriptorRequest final : public ProtoDecodableMessage {
public:
@@ -2132,7 +2236,11 @@ class BluetoothGATTWriteDescriptorRequest final : public ProtoDecodableMessage {
protected:
bool decode_length(uint32_t field_id, ProtoLengthDelimited value) override;
bool decode_varint(uint32_t field_id, ProtoVarIntResult value) override;
#ifdef USE_API_VARINT64
bool decode_varint(uint32_t field_id, uint64_t value) override;
#else
bool decode_varint(uint32_t field_id, uint32_t value) override;
#endif
};
class BluetoothGATTNotifyRequest final : public ProtoDecodableMessage {
public:
@@ -2149,7 +2257,11 @@ class BluetoothGATTNotifyRequest final : public ProtoDecodableMessage {
#endif
protected:
bool decode_varint(uint32_t field_id, ProtoVarIntResult value) override;
#ifdef USE_API_VARINT64
bool decode_varint(uint32_t field_id, uint64_t value) override;
#else
bool decode_varint(uint32_t field_id, uint32_t value) override;
#endif
};
class BluetoothGATTNotifyDataResponse final : public ProtoMessage {
public:
@@ -2329,7 +2441,11 @@ class BluetoothScannerSetModeRequest final : public ProtoDecodableMessage {
#endif
protected:
bool decode_varint(uint32_t field_id, ProtoVarIntResult value) override;
#ifdef USE_API_VARINT64
bool decode_varint(uint32_t field_id, uint64_t value) override;
#else
bool decode_varint(uint32_t field_id, uint32_t value) override;
#endif
};
#endif
#ifdef USE_VOICE_ASSISTANT
@@ -2347,7 +2463,11 @@ class SubscribeVoiceAssistantRequest final : public ProtoDecodableMessage {
#endif
protected:
bool decode_varint(uint32_t field_id, ProtoVarIntResult value) override;
#ifdef USE_API_VARINT64
bool decode_varint(uint32_t field_id, uint64_t value) override;
#else
bool decode_varint(uint32_t field_id, uint32_t value) override;
#endif
};
class VoiceAssistantAudioSettings final : public ProtoMessage {
public:
@@ -2396,7 +2516,11 @@ class VoiceAssistantResponse final : public ProtoDecodableMessage {
#endif
protected:
bool decode_varint(uint32_t field_id, ProtoVarIntResult value) override;
#ifdef USE_API_VARINT64
bool decode_varint(uint32_t field_id, uint64_t value) override;
#else
bool decode_varint(uint32_t field_id, uint32_t value) override;
#endif
};
class VoiceAssistantEventData final : public ProtoDecodableMessage {
public:
@@ -2424,7 +2548,11 @@ class VoiceAssistantEventResponse final : public ProtoDecodableMessage {
protected:
bool decode_length(uint32_t field_id, ProtoLengthDelimited value) override;
bool decode_varint(uint32_t field_id, ProtoVarIntResult value) override;
#ifdef USE_API_VARINT64
bool decode_varint(uint32_t field_id, uint64_t value) override;
#else
bool decode_varint(uint32_t field_id, uint32_t value) override;
#endif
};
class VoiceAssistantAudio final : public ProtoDecodableMessage {
public:
@@ -2444,7 +2572,11 @@ class VoiceAssistantAudio final : public ProtoDecodableMessage {
protected:
bool decode_length(uint32_t field_id, ProtoLengthDelimited value) override;
bool decode_varint(uint32_t field_id, ProtoVarIntResult value) override;
#ifdef USE_API_VARINT64
bool decode_varint(uint32_t field_id, uint64_t value) override;
#else
bool decode_varint(uint32_t field_id, uint32_t value) override;
#endif
};
class VoiceAssistantTimerEventResponse final : public ProtoDecodableMessage {
public:
@@ -2465,7 +2597,11 @@ class VoiceAssistantTimerEventResponse final : public ProtoDecodableMessage {
protected:
bool decode_length(uint32_t field_id, ProtoLengthDelimited value) override;
bool decode_varint(uint32_t field_id, ProtoVarIntResult value) override;
#ifdef USE_API_VARINT64
bool decode_varint(uint32_t field_id, uint64_t value) override;
#else
bool decode_varint(uint32_t field_id, uint32_t value) override;
#endif
};
class VoiceAssistantAnnounceRequest final : public ProtoDecodableMessage {
public:
@@ -2484,7 +2620,11 @@ class VoiceAssistantAnnounceRequest final : public ProtoDecodableMessage {
protected:
bool decode_length(uint32_t field_id, ProtoLengthDelimited value) override;
bool decode_varint(uint32_t field_id, ProtoVarIntResult value) override;
#ifdef USE_API_VARINT64
bool decode_varint(uint32_t field_id, uint64_t value) override;
#else
bool decode_varint(uint32_t field_id, uint32_t value) override;
#endif
};
class VoiceAssistantAnnounceFinished final : public ProtoMessage {
public:
@@ -2530,7 +2670,11 @@ class VoiceAssistantExternalWakeWord final : public ProtoDecodableMessage {
protected:
bool decode_length(uint32_t field_id, ProtoLengthDelimited value) override;
bool decode_varint(uint32_t field_id, ProtoVarIntResult value) override;
#ifdef USE_API_VARINT64
bool decode_varint(uint32_t field_id, uint64_t value) override;
#else
bool decode_varint(uint32_t field_id, uint32_t value) override;
#endif
};
class VoiceAssistantConfigurationRequest final : public ProtoDecodableMessage {
public:
@@ -2632,7 +2776,11 @@ class AlarmControlPanelCommandRequest final : public CommandProtoMessage {
protected:
bool decode_32bit(uint32_t field_id, Proto32Bit value) override;
bool decode_length(uint32_t field_id, ProtoLengthDelimited value) override;
bool decode_varint(uint32_t field_id, ProtoVarIntResult value) override;
#ifdef USE_API_VARINT64
bool decode_varint(uint32_t field_id, uint64_t value) override;
#else
bool decode_varint(uint32_t field_id, uint32_t value) override;
#endif
};
#endif
#ifdef USE_TEXT
@@ -2687,7 +2835,11 @@ class TextCommandRequest final : public CommandProtoMessage {
protected:
bool decode_32bit(uint32_t field_id, Proto32Bit value) override;
bool decode_length(uint32_t field_id, ProtoLengthDelimited value) override;
bool decode_varint(uint32_t field_id, ProtoVarIntResult value) override;
#ifdef USE_API_VARINT64
bool decode_varint(uint32_t field_id, uint64_t value) override;
#else
bool decode_varint(uint32_t field_id, uint32_t value) override;
#endif
};
#endif
#ifdef USE_DATETIME_DATE
@@ -2741,7 +2893,11 @@ class DateCommandRequest final : public CommandProtoMessage {
protected:
bool decode_32bit(uint32_t field_id, Proto32Bit value) override;
bool decode_varint(uint32_t field_id, ProtoVarIntResult value) override;
#ifdef USE_API_VARINT64
bool decode_varint(uint32_t field_id, uint64_t value) override;
#else
bool decode_varint(uint32_t field_id, uint32_t value) override;
#endif
};
#endif
#ifdef USE_DATETIME_TIME
@@ -2795,7 +2951,11 @@ class TimeCommandRequest final : public CommandProtoMessage {
protected:
bool decode_32bit(uint32_t field_id, Proto32Bit value) override;
bool decode_varint(uint32_t field_id, ProtoVarIntResult value) override;
#ifdef USE_API_VARINT64
bool decode_varint(uint32_t field_id, uint64_t value) override;
#else
bool decode_varint(uint32_t field_id, uint32_t value) override;
#endif
};
#endif
#ifdef USE_EVENT
@@ -2886,7 +3046,11 @@ class ValveCommandRequest final : public CommandProtoMessage {
protected:
bool decode_32bit(uint32_t field_id, Proto32Bit value) override;
bool decode_varint(uint32_t field_id, ProtoVarIntResult value) override;
#ifdef USE_API_VARINT64
bool decode_varint(uint32_t field_id, uint64_t value) override;
#else
bool decode_varint(uint32_t field_id, uint32_t value) override;
#endif
};
#endif
#ifdef USE_DATETIME_DATETIME
@@ -2936,7 +3100,11 @@ class DateTimeCommandRequest final : public CommandProtoMessage {
protected:
bool decode_32bit(uint32_t field_id, Proto32Bit value) override;
bool decode_varint(uint32_t field_id, ProtoVarIntResult value) override;
#ifdef USE_API_VARINT64
bool decode_varint(uint32_t field_id, uint64_t value) override;
#else
bool decode_varint(uint32_t field_id, uint32_t value) override;
#endif
};
#endif
#ifdef USE_UPDATE
@@ -2994,7 +3162,11 @@ class UpdateCommandRequest final : public CommandProtoMessage {
protected:
bool decode_32bit(uint32_t field_id, Proto32Bit value) override;
bool decode_varint(uint32_t field_id, ProtoVarIntResult value) override;
#ifdef USE_API_VARINT64
bool decode_varint(uint32_t field_id, uint64_t value) override;
#else
bool decode_varint(uint32_t field_id, uint32_t value) override;
#endif
};
#endif
#ifdef USE_ZWAVE_PROXY
@@ -3034,7 +3206,11 @@ class ZWaveProxyRequest final : public ProtoDecodableMessage {
protected:
bool decode_length(uint32_t field_id, ProtoLengthDelimited value) override;
bool decode_varint(uint32_t field_id, ProtoVarIntResult value) override;
#ifdef USE_API_VARINT64
bool decode_varint(uint32_t field_id, uint64_t value) override;
#else
bool decode_varint(uint32_t field_id, uint32_t value) override;
#endif
};
#endif
#ifdef USE_INFRARED
@@ -3079,7 +3255,11 @@ class InfraredRFTransmitRawTimingsRequest final : public ProtoDecodableMessage {
protected:
bool decode_32bit(uint32_t field_id, Proto32Bit value) override;
bool decode_length(uint32_t field_id, ProtoLengthDelimited value) override;
bool decode_varint(uint32_t field_id, ProtoVarIntResult value) override;
#ifdef USE_API_VARINT64
bool decode_varint(uint32_t field_id, uint64_t value) override;
#else
bool decode_varint(uint32_t field_id, uint32_t value) override;
#endif
};
class InfraredRFReceiveEvent final : public ProtoMessage {
public:
@@ -3121,7 +3301,11 @@ class SerialProxyConfigureRequest final : public ProtoDecodableMessage {
#endif
protected:
bool decode_varint(uint32_t field_id, ProtoVarIntResult value) override;
#ifdef USE_API_VARINT64
bool decode_varint(uint32_t field_id, uint64_t value) override;
#else
bool decode_varint(uint32_t field_id, uint32_t value) override;
#endif
};
class SerialProxyDataReceived final : public ProtoMessage {
public:
@@ -3161,7 +3345,11 @@ class SerialProxyWriteRequest final : public ProtoDecodableMessage {
protected:
bool decode_length(uint32_t field_id, ProtoLengthDelimited value) override;
bool decode_varint(uint32_t field_id, ProtoVarIntResult value) override;
#ifdef USE_API_VARINT64
bool decode_varint(uint32_t field_id, uint64_t value) override;
#else
bool decode_varint(uint32_t field_id, uint32_t value) override;
#endif
};
class SerialProxySetModemPinsRequest final : public ProtoDecodableMessage {
public:
@@ -3177,7 +3365,11 @@ class SerialProxySetModemPinsRequest final : public ProtoDecodableMessage {
#endif
protected:
bool decode_varint(uint32_t field_id, ProtoVarIntResult value) override;
#ifdef USE_API_VARINT64
bool decode_varint(uint32_t field_id, uint64_t value) override;
#else
bool decode_varint(uint32_t field_id, uint32_t value) override;
#endif
};
class SerialProxyGetModemPinsRequest final : public ProtoDecodableMessage {
public:
@@ -3192,7 +3384,11 @@ class SerialProxyGetModemPinsRequest final : public ProtoDecodableMessage {
#endif
protected:
bool decode_varint(uint32_t field_id, ProtoVarIntResult value) override;
#ifdef USE_API_VARINT64
bool decode_varint(uint32_t field_id, uint64_t value) override;
#else
bool decode_varint(uint32_t field_id, uint32_t value) override;
#endif
};
class SerialProxyGetModemPinsResponse final : public ProtoMessage {
public:
@@ -3225,7 +3421,11 @@ class SerialProxyRequest final : public ProtoDecodableMessage {
#endif
protected:
bool decode_varint(uint32_t field_id, ProtoVarIntResult value) override;
#ifdef USE_API_VARINT64
bool decode_varint(uint32_t field_id, uint64_t value) override;
#else
bool decode_varint(uint32_t field_id, uint32_t value) override;
#endif
};
class SerialProxyRequestResponse final : public ProtoMessage {
public:
@@ -3265,7 +3465,11 @@ class BluetoothSetConnectionParamsRequest final : public ProtoDecodableMessage {
#endif
protected:
bool decode_varint(uint32_t field_id, ProtoVarIntResult value) override;
#ifdef USE_API_VARINT64
bool decode_varint(uint32_t field_id, uint64_t value) override;
#else
bool decode_varint(uint32_t field_id, uint32_t value) override;
#endif
};
class BluetoothSetConnectionParamsResponse final : public ProtoMessage {
public:
+5 -1
View File
@@ -227,7 +227,11 @@ void ProtoDecodableMessage::decode(const uint8_t *buffer, size_t length) {
ESP_LOGV(TAG, "Invalid VarInt at offset %ld", (long) (ptr - buffer));
return;
}
if (!this->decode_varint(field_id, res)) {
#ifdef USE_API_VARINT64
if (!this->decode_varint(field_id, res.as_uint64())) {
#else
if (!this->decode_varint(field_id, res.as_uint32())) {
#endif
ESP_LOGV(TAG, "Cannot decode VarInt field %" PRIu32 " with value %" PRIu32 "!", field_id, res.as_uint32());
}
ptr += res.consumed;
+5 -1
View File
@@ -506,7 +506,11 @@ class ProtoDecodableMessage : public ProtoMessage {
protected:
~ProtoDecodableMessage() = default;
virtual bool decode_varint(uint32_t field_id, ProtoVarIntResult value) { return false; }
#ifdef USE_API_VARINT64
virtual bool decode_varint(uint32_t field_id, uint64_t value) { return false; }
#else
virtual bool decode_varint(uint32_t field_id, uint32_t value) { return false; }
#endif
virtual bool decode_length(uint32_t field_id, ProtoLengthDelimited value) { return false; }
virtual bool decode_32bit(uint32_t field_id, Proto32Bit value) { return false; }
// NOTE: decode_64bit removed - wire type 1 not supported
+31 -13
View File
@@ -193,6 +193,7 @@ class TypeInfo(ABC):
return f"case {self.number}: this->{self.field_name} = {content}; break;"
decode_varint = None
is_varint64 = False
@property
def decode_length_content(self) -> str:
@@ -461,7 +462,8 @@ class FloatType(TypeInfo):
class Int64Type(TypeInfo):
cpp_type = "int64_t"
default_value = "0"
decode_varint = "value.as_int64()"
decode_varint = "static_cast<int64_t>(value)"
is_varint64 = True
encode_func = "encode_int64"
wire_type = WireType.VARINT # Uses wire type 0
@@ -481,7 +483,8 @@ class Int64Type(TypeInfo):
class UInt64Type(TypeInfo):
cpp_type = "uint64_t"
default_value = "0"
decode_varint = "value.as_uint64()"
decode_varint = "value"
is_varint64 = True
encode_func = "encode_uint64"
wire_type = WireType.VARINT # Uses wire type 0
@@ -501,7 +504,7 @@ class UInt64Type(TypeInfo):
class Int32Type(TypeInfo):
cpp_type = "int32_t"
default_value = "0"
decode_varint = "value.as_int32()"
decode_varint = "static_cast<int32_t>(value)"
encode_func = "encode_int32"
wire_type = WireType.VARINT # Uses wire type 0
@@ -573,7 +576,7 @@ class Fixed32Type(TypeInfo):
class BoolType(TypeInfo):
cpp_type = "bool"
default_value = "false"
decode_varint = "value.as_bool()"
decode_varint = "value != 0"
encode_func = "encode_bool"
wire_type = WireType.VARINT # Uses wire type 0
@@ -1151,7 +1154,7 @@ class FixedArrayBytesType(TypeInfo):
class UInt32Type(TypeInfo):
cpp_type = "uint32_t"
default_value = "0"
decode_varint = "value.as_uint32()"
decode_varint = "value"
encode_func = "encode_uint32"
wire_type = WireType.VARINT # Uses wire type 0
@@ -1175,7 +1178,7 @@ class EnumType(TypeInfo):
@property
def decode_varint(self) -> str:
return f"static_cast<{self.cpp_type}>(value.as_uint32())"
return f"static_cast<{self.cpp_type}>(value)"
default_value = ""
wire_type = WireType.VARINT # Uses wire type 0
@@ -1262,7 +1265,7 @@ class SFixed64Type(TypeInfo):
class SInt32Type(TypeInfo):
cpp_type = "int32_t"
default_value = "0"
decode_varint = "value.as_sint32()"
decode_varint = "decode_zigzag32(value)"
encode_func = "encode_sint32"
wire_type = WireType.VARINT # Uses wire type 0
@@ -1282,7 +1285,8 @@ class SInt32Type(TypeInfo):
class SInt64Type(TypeInfo):
cpp_type = "int64_t"
default_value = "0"
decode_varint = "value.as_sint64()"
decode_varint = "decode_zigzag64(value)"
is_varint64 = True
encode_func = "encode_sint64"
wire_type = WireType.VARINT # Uses wire type 0
@@ -1620,6 +1624,10 @@ class RepeatedTypeInfo(TypeInfo):
"""
return self._ti.wire_type
@property
def is_varint64(self):
return self._ti.is_varint64
@property
def decode_varint_content(self) -> str:
# Pointer fields don't support decoding
@@ -2205,7 +2213,12 @@ def build_message_type(
cpp = ""
if decode_varint:
o = f"bool {desc.name}::decode_varint(uint32_t field_id, ProtoVarIntResult value) {{\n"
# Use conditional parameter type to match base class
o = "#ifdef USE_API_VARINT64\n"
o += f"bool {desc.name}::decode_varint(uint32_t field_id, uint64_t value) {{\n"
o += "#else\n"
o += f"bool {desc.name}::decode_varint(uint32_t field_id, uint32_t value) {{\n"
o += "#endif\n"
o += " switch (field_id) {\n"
o += indent("\n".join(decode_varint), " ") + "\n"
o += " default: return false;\n"
@@ -2213,10 +2226,15 @@ def build_message_type(
o += " return true;\n"
o += "}\n"
cpp += o
prot = (
"bool decode_varint(uint32_t field_id, ProtoVarIntResult value) override;"
)
protected_content.insert(0, prot)
prot_lines = [
"#ifdef USE_API_VARINT64",
"bool decode_varint(uint32_t field_id, uint64_t value) override;",
"#else",
"bool decode_varint(uint32_t field_id, uint32_t value) override;",
"#endif",
]
for i, line in enumerate(prot_lines):
protected_content.insert(i, line)
if decode_length:
o = f"bool {desc.name}::decode_length(uint32_t field_id, ProtoLengthDelimited value) {{\n"
o += " switch (field_id) {\n"