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:
@@ -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
|
||||
|
Reference in New Issue
Block a user