From 121318345355d62583dd66e968524dfa2bea41b0 Mon Sep 17 00:00:00 2001 From: Vivien Nicolas Date: Wed, 7 Dec 2022 22:49:39 +0100 Subject: [PATCH] [idl parser / zapxml] The field index for structs that does not explicitely declares a field id is offset by 1 (#23961) --- scripts/idl/test_xml_parser.py | 12 ++++++------ scripts/idl/zapxml/handlers/handlers.py | 11 ++++++----- 2 files changed, 12 insertions(+), 11 deletions(-) diff --git a/scripts/idl/test_xml_parser.py b/scripts/idl/test_xml_parser.py index 4a43d3fea717b3..932a5731d59268 100755 --- a/scripts/idl/test_xml_parser.py +++ b/scripts/idl/test_xml_parser.py @@ -97,15 +97,15 @@ def testCluster(self): structs=[ Struct(name='GetSomeDataRequest', fields=[ - Field(data_type=DataType(name='INT8U'), code=1, name='firstInput'), - Field(data_type=DataType(name='INT16U'), code=2, name='secondInput') + Field(data_type=DataType(name='INT8U'), code=0, name='firstInput'), + Field(data_type=DataType(name='INT16U'), code=1, name='secondInput') ], tag=StructTag.REQUEST), Struct(name='GetSomeDataResponse', fields=[ - Field(data_type=DataType(name='INT8U'), code=1, + Field(data_type=DataType(name='INT8U'), code=0, name='dataPoint1'), - Field(data_type=DataType(name='INT8U'), code=2, name='dataPoint2', + Field(data_type=DataType(name='INT8U'), code=1, name='dataPoint2', qualities=FieldQuality.OPTIONAL) ], tag=StructTag.RESPONSE, code=0x44) @@ -226,8 +226,8 @@ def testStruct(self): name='SomeStruct', qualities=StructQuality.FABRIC_SCOPED, fields=[ - Field(data_type=DataType(name='int16u'), code=1, name='FirstMember'), - Field(data_type=DataType(name='int32u'), code=2, name='SecondMember') + Field(data_type=DataType(name='int16u'), code=0, name='FirstMember'), + Field(data_type=DataType(name='int32u'), code=1, name='SecondMember') ] ) self.assertEqual(idl, diff --git a/scripts/idl/zapxml/handlers/handlers.py b/scripts/idl/zapxml/handlers/handlers.py index 6048b271ecf3ac..313fc61e8cdbb7 100644 --- a/scripts/idl/zapxml/handlers/handlers.py +++ b/scripts/idl/zapxml/handlers/handlers.py @@ -183,18 +183,19 @@ def GetNextProcessor(self, name: str, attrs): ) if 'fieldId' in attrs: - self._field_index = ParseInt(attrs['fieldId']) + field_index = ParseInt(attrs['fieldId']) else: # NOTE: code does NOT exist, so the number is incremental here # this seems a defficiency in XML format. - self._field_index += 1 + field_index = self._field_index + self._field_index = field_index + 1 if 'length' in attrs: data_type.max_length = ParseInt(attrs['length']) field = Field( data_type=data_type, - code=self._field_index, + code=field_index, name=attrs['name'], is_list=(attrs.get('array', 'false').lower() == 'true'), ) @@ -384,8 +385,6 @@ def GetArgumentField(self, attrs): if 'length' in attrs: data_type.max_length = ParseInt(attrs['length']) - self._field_index += 1 - field = Field( data_type=data_type, code=self._field_index, @@ -393,6 +392,8 @@ def GetArgumentField(self, attrs): is_list=(attrs.get('array', 'false') == 'true') ) + self._field_index += 1 + if attrs.get('optional', "false").lower() == 'true': field.qualities |= FieldQuality.OPTIONAL