From 8296f91b94a64b337f49d55b467963e74c9143f9 Mon Sep 17 00:00:00 2001 From: Andreas Lauser Date: Tue, 23 Apr 2024 12:57:13 +0200 Subject: [PATCH] EncodeState: rename `encode_atomic_value()` to `emplace_bytes()` Signed-off-by: Andreas Lauser Signed-off-by: Florian Jost --- odxtools/basicstructure.py | 2 +- odxtools/dynamiclengthfield.py | 2 +- odxtools/encodestate.py | 3 ++- odxtools/leadinglengthinfotype.py | 2 +- odxtools/minmaxlengthtype.py | 2 +- odxtools/parameters/matchingrequestparameter.py | 4 ++-- odxtools/parameters/reservedparameter.py | 2 +- odxtools/parameters/tablekeyparameter.py | 2 +- odxtools/paramlengthinfotype.py | 2 +- odxtools/standardlengthtype.py | 2 +- odxtools/staticfield.py | 2 +- 11 files changed, 13 insertions(+), 12 deletions(-) diff --git a/odxtools/basicstructure.py b/odxtools/basicstructure.py index 93c6c2e8..f558a00d 100644 --- a/odxtools/basicstructure.py +++ b/odxtools/basicstructure.py @@ -208,7 +208,7 @@ def encode_into_pdu(self, physical_value: Optional[ParameterValue], # position directly after the structure and let # EncodeState add the padding as needed. encode_state.cursor_byte_position = encode_state.origin_byte_position + self.byte_size - encode_state.emplace_atomic_value(b'', "") + encode_state.emplace_bytes(b'', "") # encode the length- and table keys. This cannot be done above # because we allow these to be defined implicitly (i.e. they diff --git a/odxtools/dynamiclengthfield.py b/odxtools/dynamiclengthfield.py index 042fd377..acd5f924 100644 --- a/odxtools/dynamiclengthfield.py +++ b/odxtools/dynamiclengthfield.py @@ -82,7 +82,7 @@ def encode_into_pdu(self, physical_value: ParameterValue, encode_state: EncodeSt # ensure the correct message size if the field is empty if len(physical_value) == 0: - encode_state.emplace_atomic_value(b"", "") + encode_state.emplace_bytes(b"", "") # move cursor and origin positions encode_state.origin_byte_position = orig_origin diff --git a/odxtools/encodestate.py b/odxtools/encodestate.py index ebcc77b5..69caedd8 100644 --- a/odxtools/encodestate.py +++ b/odxtools/encodestate.py @@ -47,7 +47,7 @@ class EncodeState: #: (needed for MinMaxLengthType, EndOfPduField, etc.) is_end_of_pdu: bool = True - def emplace_atomic_value(self, new_data: bytes, param_name: str) -> None: + def emplace_bytes(self, new_data: bytes, param_name: Optional[str] = None) -> None: pos = self.cursor_byte_position # Make blob longer if necessary @@ -60,6 +60,7 @@ def emplace_atomic_value(self, new_data: bytes, param_name: str) -> None: # the value to be inserted is bitwise "disjoint" from the # value which is already in the PDU... if self.coded_message[pos + i] & new_data[i] != 0: + param_name = "" if param_name is None else param_name warnings.warn( f"Object '{param_name}' overlaps with another parameter (bits are already set)", OdxWarning, diff --git a/odxtools/leadinglengthinfotype.py b/odxtools/leadinglengthinfotype.py index 89bf1e80..a52f7fc8 100644 --- a/odxtools/leadinglengthinfotype.py +++ b/odxtools/leadinglengthinfotype.py @@ -71,7 +71,7 @@ def encode_into_pdu(self, internal_value: AtomicOdxType, encode_state: EncodeSta is_highlow_byte_order=self.is_highlow_byte_order, ) - encode_state.emplace_atomic_value(length_bytes + value_bytes, "") + encode_state.emplace_bytes(length_bytes + value_bytes, "") @override def decode_from_pdu(self, decode_state: DecodeState) -> AtomicOdxType: diff --git a/odxtools/minmaxlengthtype.py b/odxtools/minmaxlengthtype.py index 50e81022..10be50c9 100644 --- a/odxtools/minmaxlengthtype.py +++ b/odxtools/minmaxlengthtype.py @@ -108,7 +108,7 @@ def encode_into_pdu(self, internal_value: AtomicOdxType, encode_state: EncodeSta f"(Is: {len(value_bytes)} bytes.)", EncodeError) return - encode_state.emplace_atomic_value(value_bytes, "") + encode_state.emplace_bytes(value_bytes, "") def decode_from_pdu(self, decode_state: DecodeState) -> AtomicOdxType: odxassert(decode_state.cursor_bit_position == 0, diff --git a/odxtools/parameters/matchingrequestparameter.py b/odxtools/parameters/matchingrequestparameter.py index a696ca0f..709020a5 100644 --- a/odxtools/parameters/matchingrequestparameter.py +++ b/odxtools/parameters/matchingrequestparameter.py @@ -71,8 +71,8 @@ def _encode_positioned_into_pdu(self, physical_value: Optional[ParameterValue], f"bytes, need at least {rq_pos + rq_len} bytes", EncodeError) return - encode_state.emplace_atomic_value(encode_state.triggering_request[rq_pos:rq_pos + rq_len], - self.short_name) + encode_state.emplace_bytes(encode_state.triggering_request[rq_pos:rq_pos + rq_len], + self.short_name) @override def _decode_positioned_from_pdu(self, decode_state: DecodeState) -> ParameterValue: diff --git a/odxtools/parameters/reservedparameter.py b/odxtools/parameters/reservedparameter.py index d8c87329..33520600 100644 --- a/odxtools/parameters/reservedparameter.py +++ b/odxtools/parameters/reservedparameter.py @@ -53,7 +53,7 @@ def _encode_positioned_into_pdu(self, physical_value: Optional[ParameterValue], encode_state: EncodeState) -> None: raw_data = (0).to_bytes((encode_state.cursor_bit_position + self.bit_length + 7) // 8, "big") - encode_state.emplace_atomic_value(raw_data, self.short_name) + encode_state.emplace_bytes(raw_data, self.short_name) @override def _decode_positioned_from_pdu(self, decode_state: DecodeState) -> ParameterValue: diff --git a/odxtools/parameters/tablekeyparameter.py b/odxtools/parameters/tablekeyparameter.py index 42178a6c..253dd2d4 100644 --- a/odxtools/parameters/tablekeyparameter.py +++ b/odxtools/parameters/tablekeyparameter.py @@ -185,7 +185,7 @@ def encode_placeholder_into_pdu(self, physical_value: Optional[ParameterValue], EncodeError) return - encode_state.emplace_atomic_value(bytes([0] * (size // 8)), self.short_name) + encode_state.emplace_bytes(bytes([0] * (size // 8)), self.short_name) encode_state.cursor_byte_position = max(orig_pos, encode_state.cursor_byte_position) encode_state.cursor_bit_position = 0 diff --git a/odxtools/paramlengthinfotype.py b/odxtools/paramlengthinfotype.py index dc2afd45..67ead7a8 100644 --- a/odxtools/paramlengthinfotype.py +++ b/odxtools/paramlengthinfotype.py @@ -87,7 +87,7 @@ def encode_into_pdu(self, internal_value: AtomicOdxType, encode_state: EncodeSta is_highlow_byte_order=self.is_highlow_byte_order, ) - encode_state.emplace_atomic_value(raw_data, "") + encode_state.emplace_bytes(raw_data, "") def decode_from_pdu(self, decode_state: DecodeState) -> AtomicOdxType: # First, we need to find a length key with matching ID. diff --git a/odxtools/standardlengthtype.py b/odxtools/standardlengthtype.py index 7057b2fa..beb42e3c 100644 --- a/odxtools/standardlengthtype.py +++ b/odxtools/standardlengthtype.py @@ -57,7 +57,7 @@ def encode_into_pdu(self, internal_value: AtomicOdxType, encode_state: EncodeSta base_data_type=self.base_data_type, is_highlow_byte_order=self.is_highlow_byte_order, ) - encode_state.emplace_atomic_value(raw_data, "") + encode_state.emplace_bytes(raw_data, "") @override def decode_from_pdu(self, decode_state: DecodeState) -> AtomicOdxType: diff --git a/odxtools/staticfield.py b/odxtools/staticfield.py index 1631985e..ae028770 100644 --- a/odxtools/staticfield.py +++ b/odxtools/staticfield.py @@ -72,7 +72,7 @@ def encode_into_pdu(self, physical_value: ParameterValue, encode_state: EncodeSt encode_state.cursor_byte_position = pos_before + self.item_byte_size elif pos_after - pos_before < self.item_byte_size: # add some padding bytes - encode_state.emplace_atomic_value( + encode_state.emplace_bytes( b'\x00' * (self.item_byte_size - (pos_after - pos_before)), "") @override