pystructtype.utils

utils: Utility functions for pystructtype.

Attributes

C

Functions

list_chunks(→ collections.abc.Generator[list[C]])

Yield successive n-sized chunks from a list.

int_to_bool_list(→ list[bool])

Converts an integer or a list of integers into a list of bools representing the bits.

Module Contents

pystructtype.utils.C[source]
pystructtype.utils.list_chunks[C](_list: list[C], n: int) collections.abc.Generator[list[C]][source]

Yield successive n-sized chunks from a list. :param _list: List to chunk out :param n: Size of chunks (must be > 0) :return: Generator of n-sized chunks of _list :raises ValueError: If n <= 0

pystructtype.utils.int_to_bool_list(data: int | list[int], byte_length: int) list[bool][source]

Converts an integer or a list of integers into a list of bools representing the bits. The result is in reverse order so that the Least Significant Bit is in list position 0.

ex. ord(“A”) or 0b01000001 = [True, False, False, False, False, False, True, False]

ex. [ord(“A”), ord(“B”)] or [0b01000001, 0b01000010]= [False, True, False, False, False, False, False, True, False, True, False, False, False, False, True, False]

Parameters:
  • data – Integer(s) to be converted

  • byte_length – Number of bytes to extract from integer(s)

Returns:

List of bools representing each bit in the data