Skip to content

Commit

Permalink
EncodeState: allow all classes which can be converted to bytes to s…
Browse files Browse the repository at this point in the history
…pecify bytefields

thanks to [at]kayoub5 for the suggestion!

Signed-off-by: Andreas Lauser <[email protected]>
Signed-off-by: Gerrit Ecke <[email protected]>
Signed-off-by: Florian Jost <[email protected]>
  • Loading branch information
andlaus committed May 6, 2024
1 parent 38a25cc commit 0c486ab
Showing 1 changed file with 2 additions and 2 deletions.
4 changes: 2 additions & 2 deletions odxtools/encodestate.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
# SPDX-License-Identifier: MIT
import warnings
from dataclasses import dataclass, field
from typing import Dict, Optional
from typing import Dict, Optional, SupportsBytes

from .exceptions import EncodeError, OdxWarning, odxassert, odxraise
from .odxtypes import AtomicOdxType, DataType
Expand Down Expand Up @@ -83,7 +83,7 @@ def emplace_atomic_value(

# Check that bytes and strings actually fit into the bit length
if base_data_type == DataType.A_BYTEFIELD:
if not isinstance(internal_value, (bytes, bytearray)):
if not isinstance(internal_value, (bytes, bytearray, SupportsBytes)):
odxraise()
if 8 * len(internal_value) > bit_length:
raise EncodeError(f"The bytefield {internal_value.hex()} is too large "
Expand Down

0 comments on commit 0c486ab

Please sign in to comment.