Skip to content

Commit

Permalink
improve endianness converter, wrap negative?
Browse files Browse the repository at this point in the history
  • Loading branch information
jr1221 committed May 19, 2024
1 parent b90da41 commit e831d82
Showing 1 changed file with 7 additions and 5 deletions.
12 changes: 7 additions & 5 deletions cangen/RustSynth.py
Original file line number Diff line number Diff line change
Expand Up @@ -141,12 +141,14 @@ def parse_decoders(self, field: CANPoint) -> str:
"""
base = f"reader.read_bits({field.size})"

# aware conversion from network to platform endianness
if field.endianness == "little":
base = f"{base}.swap_bytes()"

# TODO: Make this configurable based on endianness of platform
#elif field.endianness == "little":
# base = f"{base}.to_le()"
base = f"{base}.from_le()"
elif field.endianness == "big":
base = f"{base}.from_be()"
else:
print("Invalid endianness on point!")
exit(1)

if field.signed:
base = f"({base} as i{field.get_size_bits()})"
Expand Down

0 comments on commit e831d82

Please sign in to comment.