Skip to content

Commit

Permalink
[idl parser / zapxml] The field index for structs that does not expli…
Browse files Browse the repository at this point in the history
…citely declares a field id is offset by 1 (#23961)
  • Loading branch information
vivien-apple authored and pull[bot] committed Jan 4, 2023
1 parent ae1aee6 commit 1213183
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 11 deletions.
12 changes: 6 additions & 6 deletions scripts/idl/test_xml_parser.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down Expand Up @@ -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,
Expand Down
11 changes: 6 additions & 5 deletions scripts/idl/zapxml/handlers/handlers.py
Original file line number Diff line number Diff line change
Expand Up @@ -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'),
)
Expand Down Expand Up @@ -384,15 +385,15 @@ 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,
name=attrs['name'],
is_list=(attrs.get('array', 'false') == 'true')
)

self._field_index += 1

if attrs.get('optional', "false").lower() == 'true':
field.qualities |= FieldQuality.OPTIONAL

Expand Down

0 comments on commit 1213183

Please sign in to comment.