1
0
mirror of https://github.com/esphome/esphome.git synced 2025-09-22 05:02:23 +01:00

[api_protobuf.py] Use type appropriate for estimated_size (#10797)

This commit is contained in:
Keith Burzinski
2025-09-18 20:55:45 -05:00
committed by GitHub
parent 2bb64a189d
commit 9c201afe76

View File

@@ -1750,13 +1750,16 @@ def build_message_type(
# Add estimated size constant
estimated_size = calculate_message_estimated_size(desc)
# Validate that estimated_size fits in uint8_t
if estimated_size > 255:
raise ValueError(
f"Estimated size {estimated_size} for {desc.name} exceeds uint8_t maximum (255)"
)
# Use a type appropriate for estimated_size
estimated_size_type = (
"uint8_t"
if estimated_size <= 255
else "uint16_t"
if estimated_size <= 65535
else "size_t"
)
public_content.append(
f"static constexpr uint8_t ESTIMATED_SIZE = {estimated_size};"
f"static constexpr {estimated_size_type} ESTIMATED_SIZE = {estimated_size};"
)
# Add message_name method inline in header