Skip to content

Commit

Permalink
Faster Message string representation
Browse files Browse the repository at this point in the history
Improved the speed of data conversion to hex string
  • Loading branch information
pierreluctg authored Sep 12, 2024
1 parent 7302127 commit eadb555
Showing 1 changed file with 3 additions and 4 deletions.
7 changes: 3 additions & 4 deletions can/message.py
Original file line number Diff line number Diff line change
Expand Up @@ -130,12 +130,11 @@ def __str__(self) -> str:
field_strings.append(flag_string)

field_strings.append(f"DL: {self.dlc:2d}")
data_strings = []
data_strings = ""
if self.data is not None:
for index in range(0, min(self.dlc, len(self.data))):
data_strings.append(f"{self.data[index]:02x}")
data_strings = self.data[: min(self.dlc, len(self.data))].hex(" ")
if data_strings: # if not empty
field_strings.append(" ".join(data_strings).ljust(24, " "))
field_strings.append(data_strings.ljust(24, " "))
else:
field_strings.append(" " * 24)

Expand Down

0 comments on commit eadb555

Please sign in to comment.