1
0
mirror of https://github.com/esphome/esphome.git synced 2025-09-22 13:12:22 +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 # Add estimated size constant
estimated_size = calculate_message_estimated_size(desc) estimated_size = calculate_message_estimated_size(desc)
# Validate that estimated_size fits in uint8_t # Use a type appropriate for estimated_size
if estimated_size > 255: estimated_size_type = (
raise ValueError( "uint8_t"
f"Estimated size {estimated_size} for {desc.name} exceeds uint8_t maximum (255)" if estimated_size <= 255
) else "uint16_t"
if estimated_size <= 65535
else "size_t"
)
public_content.append( 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 # Add message_name method inline in header