The module macholib.ptypes defines types that can be serialized into byte arrays, both for basic types and structured types (C struct values).
Returns the size in bytes of an object when packed, raises ValueError for inappropriate values.
Returns a packable type that is a subclass of the Python type pytype. The value is converted to and from the packed format using the struct format.
All packable types are a subclass of BasePackable, which defines the basic interface but is itself an abstract base class.
The byteorder of a packed value. This will be "<"` for little endian values and ``">" for big-endian ones.
Note
the endianness option is a public value to be able to support both big- and little-endian file formats.
The name suggests that this attribute is private, this is partically for historical reasons and partially to avoid conflicts with field names in C structs.
This class method constructs the value from a subview of a mmap.mmap object. It uses bytes starting at offset ptr and reads just enough bytes to read the entire object.
This class method constructs the value by reading just enough bytes from a file-like object.
Note
The file must be opened in binary mode, that is read calls should return byte-strings and not unicode-strings.
This class method construct the value by using the struct module to parse the given bytes.
Note
contrary to what the name suggests the argument to this method is a byte-string, not a unicode-string.
This class method constructs the object from a tuple with all fields.
Returns a byte representation of the value.
Note
there is no default implementation for this method
Write a byte representation of the value to the given file-like object. The file should be opened in binary mode.
This class attribute is a list that contains the fields of the structure in the right order. Every item of this list is a tuple with 2 arguments: the first element is the name of the field, and the second the packable type for the field.
Every subclass of Structure must define _fields_ to be usefull, and the value of _fields_ should not be changed after class construction.
Other than the core functionality this module defines a number of pypackable() types that correspond to useful basic C types.
A byte string of length 1
An 8-bit signed integer
An 8-bit unsigned integer
An 16-bit signed integer
An 16-bit unsigned integer
An 32-bit signed integer
An 32-bit unsigned integer
An 64-bit signed integer
An 64-bit unsigned integer
An floating point value of type float
An floating point value of type double
Note
the module exports a number of other types with names starting with p_, such as p_int. Those types are deprecated and should not be used.