Skip to content

Commit

Permalink
Message.encode(): do not raise an exception for blobs of incorrect si…
Browse files Browse the repository at this point in the history
…ze in container frames

There are some (relatively rare) cases were one might want to produce
frames that are not fully correct, e.g., when making unit tests...

Signed-off-by: Andreas Lauser <[email protected]>
Signed-off-by: Alexander Walz <[email protected]>
  • Loading branch information
andlaus committed Nov 15, 2023
1 parent 02f6afa commit 1bba0e8
Showing 1 changed file with 8 additions and 7 deletions.
15 changes: 8 additions & 7 deletions src/cantools/database/can/message.py
Original file line number Diff line number Diff line change
Expand Up @@ -851,15 +851,16 @@ def _encode_container(self,
if isinstance(value, bytes):
# raw data

# ensure that the size of the blob corresponds to the
# one specified by the featured message.
# produce a message if size of the blob does not
# correspond to the size specified by the message
# which it represents.
if contained_message is not None and \
len(value) != contained_message.length:
len(value) != contained_message.length:

raise EncodeError(f'Specified data for contained message '
f'{contained_message.name} is '
f'{len(value)} bytes instead of '
f'{contained_message.length} bytes')
LOGGER.info(f'Specified data for contained message '
f'{contained_message.name} is '
f'{len(value)} bytes instead of '
f'{contained_message.length} bytes')

contained_payload = value

Expand Down

0 comments on commit 1bba0e8

Please sign in to comment.