bpod_core.misc.extend_packed

bpod_core.misc.extend_packed(byte_array, values, fmt) None

Extend a bytearray with packed binary values.

This function takes a sequence of integers, converts each one to bytes using the specified struct format character, and appends the result to the given bytearray. All values use the same format character and are packed in little-endian byte order.

Parameters:
  • byte_array (bytearray) – The bytearray that will be modified in-place by appending the packed binary data.

  • values (Sequence[int]) – Integer values to convert to binary. The number of values determines how many times the format character is repeated.

  • fmt (str) – A single struct format character that defines how each value is encoded. Common options: ‘b’ (int8), ‘h’ (int16), ‘i’ (int32), ‘q’ (int64), ‘B’ (uint8), ‘H’ (uint16), ‘I’ (uint32), ‘Q’ (uint64).

Return type:

None

Examples

>>> from bpod_core.misc import extend_packed
>>> buffer = bytearray()
>>> extend_packed(buffer, [1, 2, 3], 'i')
>>> len(buffer)
12
>>> buffer.hex()
'010000000200000003000000'