uctypes -- Access binary data in a structured way. ================================================== .. This document was autogenerated by Sphinx-autoapi from a .pyi stub or a source code file. .. Do not edit this file, instead edit the source file and run Sphinx to update. .. Source: docs/stubs/uctypes/__init__.pyi .. py:module:: uctypes .. autoapi-nested-parse:: Access binary data in a structured way. This module implements "foreign data interface" for MicroPython. The idea behind it is similar to CPython's ``ctypes`` modules, but the actual API is different, streamlined and optimized for small size. The basic idea of the module is to define data structure layout with about the same power as the C language allows, and then access it using familiar dot-syntax to reference sub-fields. Attributes ---------- .. autoapisummary:: uctypes.ARRAY uctypes.BIG_ENDIAN uctypes.FLOAT32 uctypes.FLOAT64 uctypes.INT16 uctypes.INT32 uctypes.INT64 uctypes.INT8 uctypes.LITTLE_ENDIAN uctypes.NATIVE uctypes.PTR uctypes.UINT16 uctypes.UINT32 uctypes.UINT64 uctypes.UINT8 uctypes.VOID Classes ------- .. autoapisummary:: uctypes.struct Functions --------- .. autoapisummary:: uctypes.addressof uctypes.bytearray_at uctypes.bytes_at uctypes.sizeof Module Contents --------------- .. py:class:: struct(addr, descriptor, layout_type=NATIVE) Instantiate a "foreign data structure" object based on structure address in memory, descriptor (encoded as a dictionary), and layout type (see below). .. py:function:: addressof(obj) -> int Return address of an object. Argument should be bytes, bytearray or other object supporting buffer protocol (and address of this buffer is what actually returned). .. py:function:: bytearray_at(addr, size) -> bytearray Capture memory at the given address and size as bytearray object. Unlike bytes_at() function above, memory is captured by reference, so it can be both written too, and you will access current value at the given memory address. .. py:function:: bytes_at(addr, size) -> bytes Capture memory at the given address and size as bytes object. As bytes object is immutable, memory is actually duplicated and copied into bytes object, so if memory contents change later, created object retains original value. .. py:function:: sizeof(struct, layout_type=NATIVE) -> int Return size of data structure in bytes. The *struct* argument can be either a structure class or a specific instantiated structure object (or its aggregate field). .. py:data:: ARRAY :type: _typeshed.Incomplete Type constants for pointers and arrays. Note that there is no explicit constant for structures, it's implicit: an aggregate type without ``PTR`` or ``ARRAY`` flags is a structure. .. py:data:: BIG_ENDIAN :type: _typeshed.Incomplete Layout type for a big-endian packed structure. .. py:data:: FLOAT32 :type: _typeshed.Incomplete Floating-point types for structure descriptors. .. py:data:: FLOAT64 :type: _typeshed.Incomplete Floating-point types for structure descriptors. .. py:data:: INT16 :type: int Integer types for structure descriptors. Constants for 8, 16, 32, and 64 bit types are provided, both signed and unsigned. .. py:data:: INT32 :type: int Integer types for structure descriptors. Constants for 8, 16, 32, and 64 bit types are provided, both signed and unsigned. .. py:data:: INT64 :type: int Integer types for structure descriptors. Constants for 8, 16, 32, and 64 bit types are provided, both signed and unsigned. .. py:data:: INT8 :type: int Integer types for structure descriptors. Constants for 8, 16, 32, and 64 bit types are provided, both signed and unsigned. .. py:data:: LITTLE_ENDIAN :type: bytes Layout type for a little-endian packed structure. (Packed means that every field occupies exactly as many bytes as defined in the descriptor, i.e. the alignment is 1). .. py:data:: NATIVE :type: _typeshed.Incomplete Layout type for a native structure - with data endianness and alignment conforming to the ABI of the system on which MicroPython runs. .. py:data:: PTR :type: _typeshed.Incomplete Type constants for pointers and arrays. Note that there is no explicit constant for structures, it's implicit: an aggregate type without ``PTR`` or ``ARRAY`` flags is a structure. .. py:data:: UINT16 :type: int Integer types for structure descriptors. Constants for 8, 16, 32, and 64 bit types are provided, both signed and unsigned. .. py:data:: UINT32 :type: int Integer types for structure descriptors. Constants for 8, 16, 32, and 64 bit types are provided, both signed and unsigned. .. py:data:: UINT64 :type: int Integer types for structure descriptors. Constants for 8, 16, 32, and 64 bit types are provided, both signed and unsigned. .. py:data:: UINT8 :type: int Integer types for structure descriptors. Constants for 8, 16, 32, and 64 bit types are provided, both signed and unsigned. .. py:data:: VOID :type: _typeshed.Incomplete ``VOID`` is an alias for ``UINT8``, and is provided to conveniently define C's void pointers: ``(uctypes.PTR, uctypes.VOID)``.