From e6060b9f36a75952dac2d3d1f9eedb264cb9622e Mon Sep 17 00:00:00 2001 From: Matt Woodward <46688854+woodfell@users.noreply.github.com> Date: Tue, 21 Nov 2023 12:05:23 +1100 Subject: [PATCH] Fix decoding fixed length arrays of struct in python sbp2json [AP-946] (#1378) # Description @swift-nav/devinfra Alter the python decoding generated code so that fixed length arrays which contain structs (as opposed to primitive types) are properly decoded with the correct parser for the filled type. Variable length arrays are already decoded properly in all cases, it's only fixed length arrays which are broken. Only the python binding are affected by this bug. # API compatibility Sort of. The output of the python version of `sbp2json` changes. Currently messages which contain a fixed length array of structs are decoded as byte arrays in the python version of sbp2json. This is misleading. The rust version of sbp2json is able to decode these constructs properly. Therefore the output of the python and rust version of `sbp2json` can differ given identical inputs. In the current definition there are only 3 message types which suffer from this behaviour - `MsgTrackingIq`, `MsgTrackingIqDepA`, `MsgTrackingIqDepB` - all very rare and not really seen in the wild. Therefore compatibility risk is practically zero. ## API compatibility plan None required # JIRA Reference https://swift-nav.atlassian.net/browse/AP-946 --- generator/sbpg/targets/python.py | 2 +- python/sbp/RELEASE-VERSION | 2 +- python/sbp/tracking.py | 6 +++--- 3 files changed, 5 insertions(+), 5 deletions(-) diff --git a/generator/sbpg/targets/python.py b/generator/sbpg/targets/python.py index d9789bdd08..b48da0447f 100755 --- a/generator/sbpg/targets/python.py +++ b/generator/sbpg/targets/python.py @@ -72,7 +72,7 @@ def construct_format(f, type_map=CONSTRUCT_CODE): f_ = copy.copy(f) f_.type_id = fill s = f.options.get('size', None).value - return "'{id}' / construct.Array({size}, {type})".format(id=f.identifier, size=s, type=type_map.get(f_.type_id, 'construct.Byte')) + return "'{id}' / construct.Array({size}, {type})".format(id=f.identifier, size=s, type=type_map.get(f_.type_id, f'{fill}._parser')) elif f.type_id == 'array': fill = f.options['fill'].value if type_map.get(fill): diff --git a/python/sbp/RELEASE-VERSION b/python/sbp/RELEASE-VERSION index 26611488b0..50e2274e6d 100644 --- a/python/sbp/RELEASE-VERSION +++ b/python/sbp/RELEASE-VERSION @@ -1 +1 @@ -5.0.3 \ No newline at end of file +5.0.3 diff --git a/python/sbp/tracking.py b/python/sbp/tracking.py index a598600948..0f178cc61e 100644 --- a/python/sbp/tracking.py +++ b/python/sbp/tracking.py @@ -887,7 +887,7 @@ class MsgTrackingIq(SBP): _parser = construct.Struct( 'channel' / construct.Int8ul, 'sid' / GnssSignal._parser, - 'corrs' / construct.Array(3, construct.Byte),) + 'corrs' / construct.Array(3, TrackingChannelCorrelation._parser),) __slots__ = [ 'channel', 'sid', @@ -992,7 +992,7 @@ class MsgTrackingIqDepB(SBP): _parser = construct.Struct( 'channel' / construct.Int8ul, 'sid' / GnssSignal._parser, - 'corrs' / construct.Array(3, construct.Byte),) + 'corrs' / construct.Array(3, TrackingChannelCorrelationDep._parser),) __slots__ = [ 'channel', 'sid', @@ -1097,7 +1097,7 @@ class MsgTrackingIqDepA(SBP): _parser = construct.Struct( 'channel' / construct.Int8ul, 'sid' / GnssSignalDep._parser, - 'corrs' / construct.Array(3, construct.Byte),) + 'corrs' / construct.Array(3, TrackingChannelCorrelationDep._parser),) __slots__ = [ 'channel', 'sid',