MemCStruct
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 |
__mem__ |
mutable character buffer |
|
__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/mem_cstruct.py
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 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 |
|
memcpy(destination, source, num)
Copies the values of num bytes from source to the struct memory
Parameters:
Name | Type | Description | Default |
---|---|---|---|
destination |
int
|
destination address |
required |
source |
bytes
|
source data to be copied |
required |
num |
int
|
number of bytes to copy |
required |
Source code in cstruct/mem_cstruct.py
87 88 89 90 91 92 93 94 95 96 |
|
pack()
Pack the structure data into bytes
Returns:
Name | Type | Description |
---|---|---|
bytes |
bytes
|
The packed structure |
Source code in cstruct/mem_cstruct.py
98 99 100 101 102 103 104 105 |
|
set_flexible_array_length(flexible_array_length)
Set flexible array length (i.e. number of elements)
Parameters:
Name | Type | Description | Default |
---|---|---|---|
flexible_array_length |
Optional[int]
|
flexible array length |
required |
Source code in cstruct/mem_cstruct.py
107 108 109 110 111 112 113 114 115 116 117 118 119 |
|
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/mem_cstruct.py
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 |
|