Skip to content

Commit

Permalink
EncodeState: rename encode_atomic_value() to emplace_bytes()
Browse files Browse the repository at this point in the history
Signed-off-by: Andreas Lauser <[email protected]>
Signed-off-by: Florian Jost <[email protected]>
  • Loading branch information
andlaus committed Apr 23, 2024
1 parent 9bc7cf5 commit 8296f91
Show file tree
Hide file tree
Showing 11 changed files with 13 additions and 12 deletions.
2 changes: 1 addition & 1 deletion odxtools/basicstructure.py
Original file line number Diff line number Diff line change
Expand Up @@ -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'', "<PADDING>")
encode_state.emplace_bytes(b'', "<PADDING>")

# encode the length- and table keys. This cannot be done above
# because we allow these to be defined implicitly (i.e. they
Expand Down
2 changes: 1 addition & 1 deletion odxtools/dynamiclengthfield.py
Original file line number Diff line number Diff line change
Expand Up @@ -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"", "<padding>")
encode_state.emplace_bytes(b"", "<padding>")

# move cursor and origin positions
encode_state.origin_byte_position = orig_origin
Expand Down
3 changes: 2 additions & 1 deletion odxtools/encodestate.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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 = "<UNKNOWN>" if param_name is None else param_name
warnings.warn(
f"Object '{param_name}' overlaps with another parameter (bits are already set)",
OdxWarning,
Expand Down
2 changes: 1 addition & 1 deletion odxtools/leadinglengthinfotype.py
Original file line number Diff line number Diff line change
Expand Up @@ -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, "<LEADING-LENGTH-INFO-TYPE>")
encode_state.emplace_bytes(length_bytes + value_bytes, "<LEADING-LENGTH-INFO-TYPE>")

@override
def decode_from_pdu(self, decode_state: DecodeState) -> AtomicOdxType:
Expand Down
2 changes: 1 addition & 1 deletion odxtools/minmaxlengthtype.py
Original file line number Diff line number Diff line change
Expand Up @@ -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, "<MIN-MAX-LENGTH-TYPE>")
encode_state.emplace_bytes(value_bytes, "<MIN-MAX-LENGTH-TYPE>")

def decode_from_pdu(self, decode_state: DecodeState) -> AtomicOdxType:
odxassert(decode_state.cursor_bit_position == 0,
Expand Down
4 changes: 2 additions & 2 deletions odxtools/parameters/matchingrequestparameter.py
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down
2 changes: 1 addition & 1 deletion odxtools/parameters/reservedparameter.py
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down
2 changes: 1 addition & 1 deletion odxtools/parameters/tablekeyparameter.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion odxtools/paramlengthinfotype.py
Original file line number Diff line number Diff line change
Expand Up @@ -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, "<PARAM-LENGTH-INFO-TYPE>")
encode_state.emplace_bytes(raw_data, "<PARAM-LENGTH-INFO-TYPE>")

def decode_from_pdu(self, decode_state: DecodeState) -> AtomicOdxType:
# First, we need to find a length key with matching ID.
Expand Down
2 changes: 1 addition & 1 deletion odxtools/standardlengthtype.py
Original file line number Diff line number Diff line change
Expand Up @@ -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, "<STANDARD-LENGTH-TYPE>")
encode_state.emplace_bytes(raw_data, "<STANDARD-LENGTH-TYPE>")

@override
def decode_from_pdu(self, decode_state: DecodeState) -> AtomicOdxType:
Expand Down
2 changes: 1 addition & 1 deletion odxtools/staticfield.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)), "<PADDING>")

@override
Expand Down

0 comments on commit 8296f91

Please sign in to comment.