Skip to content

Commit

Permalink
Fix decoding fixed length arrays of struct in python sbp2json [AP-946] (
Browse files Browse the repository at this point in the history
#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
  • Loading branch information
woodfell authored Nov 21, 2023
1 parent c1c8eff commit e6060b9
Show file tree
Hide file tree
Showing 3 changed files with 5 additions and 5 deletions.
2 changes: 1 addition & 1 deletion generator/sbpg/targets/python.py
Original file line number Diff line number Diff line change
Expand Up @@ -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):
Expand Down
2 changes: 1 addition & 1 deletion python/sbp/RELEASE-VERSION
Original file line number Diff line number Diff line change
@@ -1 +1 @@
5.0.3
5.0.3
6 changes: 3 additions & 3 deletions python/sbp/tracking.py
Original file line number Diff line number Diff line change
Expand Up @@ -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',
Expand Down Expand Up @@ -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',
Expand Down Expand Up @@ -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',
Expand Down

0 comments on commit e6060b9

Please sign in to comment.