add bit_len to Bytes

This commit is contained in:
S Groesz 2021-04-17 05:01:32 +00:00
parent ecc1b3bd8d
commit 49ef87f8c9
1 changed files with 8 additions and 2 deletions

View File

@ -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):
"""