Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[DEV] Actions, Message Digests, Documentation Updates #17

Merged
merged 17 commits into from
Dec 30, 2024

Conversation

MatrixEditor
Copy link
Owner

Documentation Updates

  • Tutorial is now split into multiple files
  • Most of the common fields are now documented

Actions 🆕

An action can be used to execute custom logic (such as modifying the IO stream) before the next field is processed. For example, it could be used to trigger checksum or hash calculations before reading a struct field.

There are two types of actions:

  1. Packing actions: triggered before packing the data into the struct (i.e., before serializing or encoding).
  2. Unpacking actions: triggered before unpacking the data from the struct (i.e., before deserializing or decoding).

Example:

>>> def checksum_action(context: _ContextLike) -> None:
...     # This action could perform some checksum or logging logic
...     pass
...
>>> @struct
... class MyStruct:
...     some_field: Bytes(10)
...     checksum: Action(checksum_action) # runs only when packing

New Classes

  • Alignedand Align
  • Digest
  • IOHook

Fixes and Changes

  • uuidclass has been renamed to Uuid
  • Pickled class got removed
  • Renamed FormatField to PyStructFormattedField
  • Prefixed now supports arbitrary structs
  • Fixed an issue with S_ADD_BYTES resulting in an error when calling __bytes__

---

+ updated pack_into and unpack docs
---

+ String
+ ConstString
+ ConstBytes
+ CString
+ Computed
+ Pass
+ Prefixed:
   behaviour changed: uses a struct to parse
   extracted bytes rather than returning them
+ Int, UInt
# New: Aligned, align (func)
---

+ Renamed uuid to Uuid
+ added imports for align and Aligned
---

+ updated docs accordingly
---

+ Updated comparison script to use Prefixed encoding argument
+ New attribute for context protocol __context_setattr__
+ Updated docs for compression fields
---

+ Update action concept: to distinguish packing and unpacking, two attributes can be defined
---

+ Fix broken reference in index of docs
---

+ FIxes compile errors with layer.c
---

+ remove unnecessary mode checks in digest verification
@MatrixEditor MatrixEditor merged commit 21f3d85 into master Dec 30, 2024
6 checks passed
@MatrixEditor MatrixEditor deleted the dev/py-docs branch December 30, 2024 18:04
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant