Skip to content

Commit 5a8a7c6

Browse files
committed
Update README.md
1 parent 5bca4a1 commit 5a8a7c6

File tree

1 file changed

+27
-4
lines changed

1 file changed

+27
-4
lines changed

README.md

Lines changed: 27 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -161,11 +161,16 @@ class Packet(cstruct.MemCStruct):
161161

162162
### Byte Order, Size, and Padding
163163

164-
Suported byte orders:
164+
Python-CStruct supports big-endian, little-endian, and native byte orders, which you can specify using:
165165

166-
* `cstruct.LITTLE_ENDIAN` - Little endian byte order, standard size, no padding
167-
* `cstruct.BIG_ENDIAN` - Big endian byte order, standard size, no padding
168-
* `cstruct.NATIVE_ORDER` - Native byte order, native size, padding
166+
* `cstruct.LITTLE_ENDIAN` - Little endian byte order, standard size, no padding.
167+
* `cstruct.BIG_ENDIAN` - Big endian byte order, standard size, no padding.
168+
* `cstruct.NATIVE_ORDER` - Native byte order, native size, padding. Native byte order is big-endian or little-endian, depending on the host system.
169+
170+
Standard size depends only on the format character while native size depends on the host system.
171+
For native order, padding is automatically added to align the structure members.
172+
173+
For more information, see the [struct - Byte Order, Size, and Padding](https://docs.python.org/3/library/struct.html#byte-order-size-and-alignment) section.
169174

170175
```python
171176
class Native(cstruct.MemCStruct):
@@ -321,6 +326,24 @@ class MBR(cstruct.MemCStruct):
321326
"""
322327
```
323328

329+
### Accessing Field Definitions
330+
331+
Python-CStruct provides the `__fields_types__` attribute at the class level, which allows you to inspect the metadata of each field.
332+
The dictionary contains each field's name as a key and its metadata as a value.
333+
Each field has the following attributes:
334+
335+
| Attribute | Description |
336+
|------------------|------------|
337+
| `kind` | Indicates whether the field is a primitive type or a nested struct. |
338+
| `c_type` | The corresponding C type. |
339+
| `ref` | If the field is a nested struct, this contains a reference to the class representing that struct. |
340+
| `vlen_ex` | The number of elements in the field. |
341+
| `flexible_array` | Indicates whether the field is a flexible array. |
342+
| `byte_order` | The byte order of the field. |
343+
| `offset` | The relative position of the field within the struct. |
344+
| `padding` | The number of bytes added before this field for alignment. |
345+
346+
324347
### Ispect memory
325348

326349
The [`inspect`](https://python-cstruct.readthedocs.io/en/latest/api/abstract/#cstruct.abstract.AbstractCStruct.inspect) methods displays memory contents in hexadecimal.

0 commit comments

Comments
 (0)