def serialize(self, value: Sequence[bool]) -> bytes: if len(value) != self.bit_count: raise SerializationError( f"Cannot serialize length {len(value)} bit array as Bitvector[{self.bit_count}]" ) return bytes( get_serialized_bytearray(value, self.bit_count, extra_byte=False))
def serialize(self, value: Sequence[bool]) -> bytes: len_value = len(value) if len_value > self.max_bit_count: raise SerializationError( f"Cannot serialize length {len_value} bit array as Bitlist[{self.max_bit_count}]" ) serialized_bytearray = get_serialized_bytearray(value, len_value, extra_byte=True) serialized_bytearray[len_value // 8] |= 1 << (len_value % 8) return bytes(serialized_bytearray)