unpack#

swordfish.function.unpack()#

Unpack from the buf according to the format string specified by format. The result is a tuple with the unpacked data even if it contains exactly one item.

Parameters:
  • format (Constant) –

    A format string.

    • A format character may be preceded by an integral repeat count. For example, the format string ‘4h’ means exactly the same as ‘hhhh’.

    • Whitespace characters between formats are ignored; a count and its format must not contain whitespace though.

    • For the ‘s’ format character, the count is interpreted as the length of the bytes, not a repeat count like for the other format characters; for example, ’10s’ means a single 10-byte string, while ‘10c’ means 10 characters. If a count is not given, it defaults to 1. The string is truncated or padded with null bytes as appropriate to make it fit.

  • buffer (Constant) – A bytes object of STRING or BLOB type. The size of buf in bytes must match the size required by the format.