diff --git a/src/bits.py b/src/bits.py index 219c612..b34d5be 100644 --- a/src/bits.py +++ b/src/bits.py @@ -935,7 +935,7 @@ class Bytes: import sys - def __init__(self, var=None, byteorder="big"): + def __init__(self, var=None, byteorder="big", bits=None): """ var: a supported variant (object) byteorder: notimplemented, mostly ignored @@ -943,11 +943,17 @@ class Bytes: self.__raw = bytearray(b'') self.__small = False self.__iter = None - self.__list_len = None + self.__bit_len = None if byteorder.lower() in ["small", "little"]: self.__small = True if var is not None: self.__raw = self.__to_bytearray(var) + if bits is None: + self.__bit_len = len(self.__raw) + else: + if not isinstance(bits, (int, Bytes, Bit)): + raise TypeError(f"bits argument must be int, not {type(bits)}") + self.__bit_len = int(bits) def __bytes__(self): """