CStruct
Bases: AbstractCStruct
Convert C struct definitions into Python classes.
Attributes:
Name | Type | Description |
---|---|---|
__struct__ |
str
|
definition of the struct (or union) in C syntax |
__byte_order__ |
str
|
byte order, valid values are LITTLE_ENDIAN, BIG_ENDIAN, NATIVE_ORDER |
__is_union__ |
bool
|
True for union definitions, False for struct definitions |
__size__ |
int
|
size of the structure in bytes (flexible array member size is omitted) |
__fields__ |
list
|
list of structure fields |
__fields_types__ |
dict
|
dictionary mapping field names to types |
Source code in cstruct/cstruct.py
30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 |
|
pack()
Pack the structure data into bytes
Returns:
Name | Type | Description |
---|---|---|
bytes |
bytes
|
The packed structure |
Source code in cstruct/cstruct.py
59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 |
|
unpack_from(buffer, offset=0, flexible_array_length=None)
Unpack bytes containing packed C structure data
Parameters:
Name | Type | Description | Default |
---|---|---|---|
buffer |
Optional[bytes]
|
bytes to be unpacked |
required |
offset |
int
|
optional buffer offset |
0
|
flexible_array_length |
Optional[int]
|
optional flexible array lenght (number of elements) |
None
|
Source code in cstruct/cstruct.py
43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 |
|