What's Changed
Documentation Updates
- The tutorial was reorganized into multiple files for easier navigation and a more structured learning experience. This should make it easier to find what you need and dive into the specifics of different topics.
- Most of the common field types are now fully documented, providing clear, comprehensive examples and explanations for quick reference.
New Feature: Actions
Actions introduce the ability to execute custom logic before processing a field, allowing you to modify the IO stream or perform operations like checksum calculations or logging. There are two types of actions:
- Packing actions (
__action_pack__
): Triggered before packing the data into a struct, typically used for operations before serializing or encoding. - Unpacking actions(
__action_unpack__
): Triggered before unpacking the data from a struct, useful for tasks before deserializing or decoding.
def checksum_action(context: _ContextLike) -> None:
# Perform checksum or logging logic here
pass
@struct
class MyStruct:
some_field: Bytes(10)
checksum: Action(checksum_action) # Runs only when packing
New Classes
-
Aligned
andAlign
: These help manage data alignment, ensuring your structs are correctly aligned in memory or when serialized. -
Digest
: A new class designed to handle cryptographic hashes or checksums within your structs.from caterpillar.py import struct, Bytes, Md5 @struct class Format: # Appends a new attribute AFTER all fields within the # context and verifies after parsing the data with Md5(name="hash", verify=True): user_data: Bytes(100)
-
IOHook
: A class to hook into the IO process, allowing further customization of data reading and writing.
Fixes and Changes
- Class Rename: The
uuid
class has been renamed toUuid
for consistency and clarity. - Removed Class: The
Pickled
class has been removed in favor of more flexible serialization options. - Renaming:
FormatField
has been renamed toPyStructFormattedField
to better reflect its usage. Prefixed
Enhancement: ThePrefixed
class now supports arbitrary structs, offering more flexibility when dealing with prefixed data.- Bug Fix: A bug in
S_ADD_BYTES
has been fixed, which previously caused an error when calling__bytes__
.
- [HOTFIX] C API Bugfixes by @MatrixEditor in #13
- [DEV] Annotation Registry by @MatrixEditor in #16
- [DEV] Actions, Message Digests, Documentation Updates by @MatrixEditor in #17
Full Changelog: v2.2.0...v2.4.0