ustruct.rst 1.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142
  1. :mod:`ustruct` -- pack and unpack primitive data types
  2. ======================================================
  3. .. module:: ustruct
  4. :synopsis: pack and unpack primitive data types
  5. |see_cpython_module| :mod:`python:struct`.
  6. Supported size/byte order prefixes: ``@``, ``<``, ``>``, ``!``.
  7. Supported format codes: ``b``, ``B``, ``h``, ``H``, ``i``, ``I``, ``l``,
  8. ``L``, ``q``, ``Q``, ``s``, ``P``, ``f``, ``d`` (the latter 2 depending
  9. on the floating-point support).
  10. Functions
  11. ---------
  12. .. function:: calcsize(fmt)
  13. Return the number of bytes needed to store the given *fmt*.
  14. .. function:: pack(fmt, v1, v2, ...)
  15. Pack the values *v1*, *v2*, ... according to the format string *fmt*.
  16. The return value is a bytes object encoding the values.
  17. .. function:: pack_into(fmt, buffer, offset, v1, v2, ...)
  18. Pack the values *v1*, *v2*, ... according to the format string *fmt*
  19. into a *buffer* starting at *offset*. *offset* may be negative to count
  20. from the end of *buffer*.
  21. .. function:: unpack(fmt, data)
  22. Unpack from the *data* according to the format string *fmt*.
  23. The return value is a tuple of the unpacked values.
  24. .. function:: unpack_from(fmt, data, offset=0)
  25. Unpack from the *data* starting at *offset* according to the format string
  26. *fmt*. *offset* may be negative to count from the end of *buffer*. The return
  27. value is a tuple of the unpacked values.