-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Adds Structure collection documentation and examples.
- Loading branch information
Showing
2 changed files
with
332 additions
and
49 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1 +1,28 @@ | ||
# Byteclasses Structure Collection | ||
# Structure | ||
|
||
A Structure is a dynamic byteclass created using the `@structure` decorator. | ||
|
||
```python | ||
@structure | ||
class MyStructure: | ||
"""My Structure Byteclass.""" | ||
|
||
var1: UInt64 = UInt64() | ||
var2: UInt32 = UInt32() | ||
``` | ||
|
||
Similar to a C `struct`, each member of a byteclass `structure` has a sequential offset. By default, `structure` are padded so each member is size aligned. The `structure` decorator accepts a boolean `padding` parameter to override the default padding behavior. | ||
|
||
The length of a Structure byteclass is determined when the class is created based on its members. | ||
|
||
A Structure byteclass can contain both byteclass primitives and other byteclass collections. | ||
|
||
Each Structure member has its own `byte_order`. However, the `structure` decorator accepts a `byte_order` parameter which is used for any members that rely on a `default_factory` for instantiation. | ||
|
||
```python | ||
@structure(byte_order=b">") | ||
class FactoryStructure: | ||
"""A structure byteclass with member using default factory.""" | ||
|
||
a: UInt64 = member(default_factory=UInt64) | ||
``` |
Oops, something went wrong.