Skip to content

Commit 787a807

Browse files
committed
EndOfPduField, StaticField: set the origin position during encoding
Note that this does not make a difference because all items of fields are structures, which need to set the origin position to the beginning of the structure anyway, but IMO it is conceptually clearer to explicitly set the origin position in fields as well. Signed-off-by: Andreas Lauser <[email protected]> Signed-off-by: Gerrit Ecke <[email protected]>
1 parent 459c85c commit 787a807

File tree

2 files changed

+14
-0
lines changed

2 files changed

+14
-0
lines changed

odxtools/endofpdufield.py

+7
Original file line numberDiff line numberDiff line change
@@ -71,6 +71,10 @@ def decode_from_pdu(self, decode_state: DecodeState) -> ParameterValue:
7171
odxassert(not decode_state.cursor_bit_position,
7272
"No bit position can be specified for end-of-pdu fields!")
7373

74+
orig_origin = decode_state.origin_byte_position
75+
orig_cursor = decode_state.cursor_byte_position
76+
decode_state.origin_byte_position = decode_state.cursor_byte_position
77+
7478
result: List[ParameterValue] = []
7579
while decode_state.cursor_byte_position < len(decode_state.coded_message):
7680
# ATTENTION: the ODX specification is very misleading
@@ -79,4 +83,7 @@ def decode_from_pdu(self, decode_state: DecodeState) -> ParameterValue:
7983
# repeated are identical, not their values
8084
result.append(self.structure.decode_from_pdu(decode_state))
8185

86+
decode_state.origin_byte_position = orig_origin
87+
decode_state.cursor_byte_position = max(orig_cursor, decode_state.cursor_byte_position)
88+
8289
return result

odxtools/staticfield.py

+7
Original file line numberDiff line numberDiff line change
@@ -88,6 +88,10 @@ def decode_from_pdu(self, decode_state: DecodeState) -> ParameterValue:
8888
odxassert(decode_state.cursor_bit_position == 0,
8989
"No bit position can be specified for static length fields!")
9090

91+
orig_origin = decode_state.origin_byte_position
92+
orig_cursor = decode_state.cursor_byte_position
93+
decode_state.origin_byte_position = decode_state.cursor_byte_position
94+
9195
result: List[ParameterValue] = []
9296
for _ in range(self.fixed_number_of_items):
9397
orig_cursor = decode_state.cursor_byte_position
@@ -101,4 +105,7 @@ def decode_from_pdu(self, decode_state: DecodeState) -> ParameterValue:
101105

102106
decode_state.cursor_byte_position = orig_cursor + self.item_byte_size
103107

108+
decode_state.origin_byte_position = orig_origin
109+
decode_state.cursor_byte_position = max(orig_cursor, decode_state.cursor_byte_position)
110+
104111
return result

0 commit comments

Comments
 (0)