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 inFieldMixin, is to return a newFieldinstance with the byteorder applied. Note the use of another operator here.>>> field = BigEndian + struct
Added in version 2.10.0: Classes created via
struct()orbitfield()also implement__set_byteorder__()(installed as aclassmethod), 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.