3.2.3.6. Byteorder Extensions#

object.__byteorder__#

The byteorder of a struct can be temporarily configured using the corresponding operator. It is important to note that this attribute is utilized internally and should not be used elsewhere.

>>> struct = BigEndian | struct # Automatically sets __byteorder__
object.__set_byteorder__(self, byteorder)#

In contrast to the attribute __byteorder__, the __set_byteorder__() method is invoked to apply the current byteorder to a struct. The default behavior, as described in FieldMixin, is to return a new Field instance with the byteorder applied. Note the use of another operator here.

>>> field = BigEndian + struct

Added in version 2.10.0: Classes created via struct() or bitfield() also implement __set_byteorder__() (installed as a classmethod), so the very same operator syntax works directly on a struct class rather than only on field/atom instances:

>>> @struct(order=Inherit)
... class Inner:
...     value: uint32
...
>>> field = LittleEndian + Inner  # Field(Inner, order=LittleEndian)

See the byte order tutorial for more details.