Files
pybricks-api/doc/main/micropython/ustruct.rst
T

57 lines
2.8 KiB
ReStructuredText

.. pybricks-requirements:: stm32-extra
:mod:`ustruct` -- Pack and unpack binary data
====================================================
.. automodule:: ustruct
The following byte orders are supported:
+-----------+------------------------+----------+-----------+
| Character | Byte order | Size | Alignment |
+===========+========================+==========+===========+
| @ | native | native | native |
+-----------+------------------------+----------+-----------+
| < | little-endian | standard | none |
+-----------+------------------------+----------+-----------+
| > | big-endian | standard | none |
+-----------+------------------------+----------+-----------+
| ! | network (= big-endian) | standard | none |
+-----------+------------------------+----------+-----------+
The following data types are supported:
+--------+--------------------+-------------+---------------+
| Format | C Type | Python type | Standard size |
+========+====================+=============+===============+
| b | signed char | integer | 1 |
+--------+--------------------+-------------+---------------+
| B | unsigned char | integer | 1 |
+--------+--------------------+-------------+---------------+
| h | short | integer | 2 |
+--------+--------------------+-------------+---------------+
| H | unsigned short | integer | 2 |
+--------+--------------------+-------------+---------------+
| i | int | integer | 4 |
+--------+--------------------+-------------+---------------+
| I | unsigned int | integer | 4 |
+--------+--------------------+-------------+---------------+
| l | long | integer (1) | 4 |
+--------+--------------------+-------------+---------------+
| L | unsigned long | integer (1) | 4 |
+--------+--------------------+-------------+---------------+
| q | long long | integer (1) | 8 |
+--------+--------------------+-------------+---------------+
| Q | unsigned long long | integer (1) | 8 |
+--------+--------------------+-------------+---------------+
| f | float | float | 4 |
+--------+--------------------+-------------+---------------+
| d | double | float | 8 |
+--------+--------------------+-------------+---------------+
| s | char[] | bytes | |
+--------+--------------------+-------------+---------------+
| P | void * | integer | |
+--------+--------------------+-------------+---------------+
- \(1\) Supports values up to +/-1073741823