ctypes.BigEndianStructure
Prev: ctypes.Array | Up: ctypes | Next: ctypes.BigEndianUnion
Rel: ctypes.addressof, ctypes.alignment, ctypes.ArgumentError, ctypes.Array
Ref: docs.python.org — ctypes.BigEndianStructure
Tags: #public #python3 #stdlib #ctypes
Import
import ctypes
from ctypes import BigEndianStructure
Signature & Overview
ctypes.BigEndianStructure(...)
Structure with big endian byte order
Usage
import ctypes
class NetHeader(ctypes.BigEndianStructure):
_pack_ = 1
_fields_ = [("version", ctypes.c_uint8), ("length", ctypes.c_uint16)]
h = NetHeader.from_buffer_copy(b"\x01\x00\x2a")
assert (h.version, h.length) == (1, 42)
Gotchas
- Set
_pack_ = 1for wire protocols so C alignment padding doesn't shift field offsets.
REPL Inspect
from ctypes import BigEndianStructure
help(BigEndianStructure)
Linked from
Related notes
- tuts/python3/stdlib_module/ctypes/addressof Linked here; links to this page; shared tags: #ctypes, #stdlib
- tuts/python3/stdlib_module/ctypes/alignment Linked here; links to this page; shared tags: #ctypes, #stdlib
- tuts/python3/stdlib_module/ctypes/ArgumentError Linked here; links to this page; shared tags: #ctypes, #stdlib
- tuts/python3/stdlib_module/ctypes/Array Linked here; links to this page; shared tags: #ctypes, #stdlib
- tuts/python3/stdlib_module/ctypes/BigEndianUnion Linked here; links to this page; shared tags: #ctypes, #stdlib
- tuts/python3/stdlib_module/ctypes Linked here; links to this page; shared tags: #stdlib
- tuts/python3/stdlib_module/ctypes/byref shared tags: #ctypes, #stdlib
- tuts/python3/stdlib_module/ctypes/c_bool shared tags: #ctypes, #stdlib
- tuts/python3/stdlib_module/ctypes/c_buffer shared tags: #ctypes, #stdlib
- tuts/python3/stdlib_module/ctypes/c_byte shared tags: #ctypes, #stdlib