mirror of
https://github.com/esphome/esphome.git
synced 2026-07-10 17:05:36 +00:00
e35aa729f3
Add a max_value field option to api_options.proto that tells the code generator the maximum value a field can have. When max_value < 128, the generated calculate_size() uses constant arithmetic instead of calling varint size functions, and encode() uses direct byte writes instead of varint encoding. Also optimize FixedArrayBytesType: when fixed_array_size < 128, the length varint is always 1 byte, so calculate_size() uses constant arithmetic and encode() uses write_raw_byte for the length. Applied to BluetoothLERawAdvertisement.address_type (max_value=4). Measured on ESP32 (upstairsdesk89proxy): - BluetoothLERawAdvertisement::calculate_size: 88 → 71 bytes (-19%) - BluetoothLERawAdvertisement::encode: 199 → 179 bytes (-10%) - Total BLE proxy hot path: 1807 → 1770 bytes (-37 bytes)