copapy.pack#

copapy.pack(fmt, *values)#

Convert numbers or copapy values to their bytes, like struct.pack.

The format is a struct format string limited to 32 bit types: ‘b’ and ‘B’ (8 bit int), ‘h’ and ‘H’ (16 bit int), ‘i’ and ‘I’ (32 bit int), ‘f’ (32 bit float) and ‘x’ (pad byte), with optional repeat counts. It starts with ‘<’ for little-endian (default) or ‘>’ for big-endian byte order.

Int values that do not fit into the field are truncated to its lowest bits. Numbers and constants are converted at trace time.

Parameters:
  • fmt (str) – Format string, e.g. ‘<Hhf’

  • values (value[int] | value[float] | int | float) – One int or float number or copapy value per field

Returns:

copapy int values or ints from 0 to 255

Return type:

list[value[int] | int]