diff --git a/script/api_protobuf/api_protobuf.py b/script/api_protobuf/api_protobuf.py index 81653c3302..05567629b2 100755 --- a/script/api_protobuf/api_protobuf.py +++ b/script/api_protobuf/api_protobuf.py @@ -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