From bc6b1ffc1428464d06cfed910cce0139b7f88e93 Mon Sep 17 00:00:00 2001 From: "J. Nick Koston" Date: Mon, 21 Jul 2025 13:12:30 -1000 Subject: [PATCH] cleanup --- script/api_protobuf/api_protobuf.py | 33 +++++++++++++++++------------ 1 file changed, 19 insertions(+), 14 deletions(-) diff --git a/script/api_protobuf/api_protobuf.py b/script/api_protobuf/api_protobuf.py index dedd58d5a1..453f4ffe10 100755 --- a/script/api_protobuf/api_protobuf.py +++ b/script/api_protobuf/api_protobuf.py @@ -1367,20 +1367,6 @@ def build_message_type( needs_decode = source in (SOURCE_BOTH, SOURCE_CLIENT) needs_encode = source in (SOURCE_BOTH, SOURCE_SERVER) - # Validate that fixed_array_size is only used in encode-only messages - if needs_decode: - for field in desc.field: - if ( - field.label == 3 - and get_field_opt(field, pb.fixed_array_size) is not None - ): - raise ValueError( - f"Message '{desc.name}' uses fixed_array_size on field '{field.name}' " - f"but has source={['SOURCE_BOTH', 'SOURCE_SERVER', 'SOURCE_CLIENT'][source]}. " - f"Fixed arrays are only supported for SOURCE_SERVER (encode-only) messages " - f"since we cannot trust or control the number of items received from clients." - ) - # Add MESSAGE_TYPE method if this is a service message if message_id is not None: # Validate that message_id fits in uint8_t @@ -1416,6 +1402,19 @@ def build_message_type( if field.options.deprecated: continue + # Validate that fixed_array_size is only used in encode-only messages + if ( + needs_decode + and field.label == 3 + and get_field_opt(field, pb.fixed_array_size) is not None + ): + raise ValueError( + f"Message '{desc.name}' uses fixed_array_size on field '{field.name}' " + f"but has source={SOURCE_NAMES[source]}. " + f"Fixed arrays are only supported for SOURCE_SERVER (encode-only) messages " + f"since we cannot trust or control the number of items received from clients." + ) + ti = create_field_type_info(field, needs_decode, needs_encode) # Skip field declarations for fields that are in the base class @@ -1605,6 +1604,12 @@ SOURCE_BOTH = 0 SOURCE_SERVER = 1 SOURCE_CLIENT = 2 +SOURCE_NAMES = { + SOURCE_BOTH: "SOURCE_BOTH", + SOURCE_SERVER: "SOURCE_SERVER", + SOURCE_CLIENT: "SOURCE_CLIENT", +} + RECEIVE_CASES: dict[int, tuple[str, str | None]] = {} ifdefs: dict[str, str] = {}