Prefixednow supports struct types directlyStructDefMixinnow includes direct to-bytes conversion withbytes(...)- Fixed a bug in
@bitfieldwhere parsed bit-width fields are not populated to the current context - Corrected some type hints in
FieldMixinand_ContextLike
- Python 3.14-compatible conditional field metadata:
with If(condition) as when:,f[..., when],Start(when)/End(when), explicitElseIf(previous, condition)chains, andElse(previous)fallback branches. Branch,When, andOtherwisefor conditional variants of one attribute, including branch-localf[...]options such as byte order.- Python generic templates based on normal
typing.TypeVarandGenericclasses. Templates now support directTemplate[uint8]specialization, partial specialization, specialization caching, and runtime__origin__/__args__metadata. field_of()for carrying generic template field metadata throughf[...], including sequence length, offset, switch options, byte order, bit width, and conditions.Padded,PrePad, andPostPadwrappers for explicit before/after padding, dynamic padding lengths, repeated fill patterns, strict validation, and slash syntax such asuint8 / PrePad(1) / PostPad(2).- A
pytest-benchmarkbenchmark suite covering theexamples/comparisonworkload.
derive()now handles generic templates, returns already materialized struct classes unchanged when no type arguments are supplied, supports keyword defaults in legacy templates, and evaluates deferred annotations while legacy template variables are still available.- Native C atoms (
Repeated,Conditional,AtOffset, andSwitch) now accept Python struct classes and other__struct__containers, improving Python/C interoperability andc_Contextcoverage. PyStructFormattedFieldnow handles prefixed sequence unpacking and validates empty sequence packing after processing fixed or prefixed lengths.Lazynow resolves objects that expose__struct__, allowing lazy factories to return decorated model classes or struct containers.
Fieldrejects negative sequence lengths at definition time and uses a faster no-option unpack path while preserving default fallback and exception wrapping behavior.Compressedcopies compression and decompression keyword arguments before resolving context lambdas, preventing cross-call mutation.- Fixed-length
CStringunpacking now performs exact reads and rejects truncated input. - Padding validation now covers strict greedy fill patterns and rejects unsupported prefixed padding lengths.
- C extension fixes include safer reference handling and error propagation,
length-info forwarding to
__pack_many__/__unpack_many__,__bits__lookup on Python atoms, repeated atom unpack detection,AtOffset.keep_posbehavior, switch type aggregation, arch/endian rich comparison errors, and writable offset/whence setters.
- New concept: extended syntax featuring typing compliance; introduces shortcut
fto annotate fields andInvisible()to hide fields from the constructor struct_factory.mixinandbitfield_factory.mixinboth provide default function wrappers for packing and unpacking data as well as typing fixes for operating on types directly.- New
parentctxcontext path - Dynamic endian is now used by default (i. e. can be changed via order parameter in pack() or unpack())
- New generic
Timestampclass - A number of new test cases
- New module:
caterpillar.types: defines default types that can be used as annotations within struct definitions O_DEFAULT_ENDIANas a global option to set a global default byteorderO_DEFAULT_ARCHsame concept for arch-like objects- new 'strict' option to
Enumstruct ATTR_PACKandATTR_UNPACKto caterpillar.shared'order'and'arch'options to pack() and unpack(), which temporarily change the global endianess or arch (compatible with Dynamic byteorder)
- Merge all stub files with their corresponding Python files. All typing is now inline.
paddingstruct now has its own dedicated class- sizeof() now always returns an integer
- ContextPath: dropped support for the call action
- Field.get_name() now always returns a string
- Rename
ssizeandsizetopssizeandpsizein caterpillar.fields exports - options.get_flags() always returns a list
- IntFlag support for
Enumstructs - Fix incorrect Sha1 Digest length
- Add missing global exports in
caterpillar.py - Bitfield, Struct and Sequence now respect fields with already configured byteorder
- Prefixed struct now does not require
as_field=Truewhen calling pack() or unpack()
- New concept: dynamic byte order (explained in documentation "Dynamic Byte Order")
caterpillar.field.net
- Fixed parsing of :class:
~caterpillar.fields.net.MACAddress - Fixed mixed endian in a struct, sequence or bit-field
caterpillar
- Various stub files and decorator annotations
caterpillar.field._base
- Fix 1-length sized array fields
caterpillar
- Add compatibility with at least Python 3.10 by using
typing_extensions
-
caterpillar.fields._base
- Fix switch functionality within the
Fieldclass forContextPathobjects
- Fix switch functionality within the
-
caterpillar.fields.common
- fix
%operator for theAsLengthRefclass.
- fix
-
caterpillar.fields._base
- Add support for non-context lambda switch fields.
-
caterpillar.fields.common
- Add compatibility support for CAPI atoms in
Int,UIntandPyStructFormattedField.
- Add compatibility support for CAPI atoms in
-
caterpillar.options
- Add custom
Flag.__eq__implementation to support equality check withc_Optionobjects.
- Add custom
-
caterpillar.abc
- Add new typing-only
_OptionLikeprotocol. - Add missing
_SupportsTypeprotocol to the stubs file. - Add new method
getto the_ContextLikeprotocol.
- Add new typing-only
-
caterpillar.context
- Add new option
O_CONTEXT_FACTORYthat controls the global context type. Value must be a method or another type implementing the_ContextLikeprotocol. - Add new global context path:
root(exported asGin shortcuts).
- Add new option
-
caterpillar.shortcuts
- Add new shortcuts
Cforctx,PforparentandGfor therootcontext asContextPathobjects.
- Add new shortcuts
-
CAPI
- New index assignment system when generating CAPI code — a running number is now applied instead of a hard-coded index.
- Add complete Context implementation in C (
c_Context) that conforms to the_ContextLikeprotocol. - Add
Atomfor C-based struct-like classes (previously known ascatom). - Add native support for
__bits__inAtom. - Add special class
LengthInfofor packing or unpacking multiple objects. - New builtin atoms (CAPI):
Repeated,ConditionalandSwitch. - Add new shared objects and exception types to the native implementation (
Cp_ContextFactory,Cp_ArrayFactory,CpExc_StopandCp_DefaultOption).
- caterpillar.fields._base
- Rework
Fieldimplementation to reduce overhead when packing and unpacking elements. - Use pre-computed states instead of calculating everything on the fly; states will be adjusted automatically when setting new values (via
@propertyattributes).
- Rework
- caterpillar.fields.common
- Fix issue in
Prefixedthat occurred when the internal struct packs a sequence of elements.
- Fix issue in
- CAPI
- Remove old CAPI and completely revamp the CAPI concept to make it compatible with the Python equivalent.
- caterpillar.model
- An issue when packing or unpacking a bitfield with unnamed fields AND
S_DISCARD_UNNAMEDenabled
- An issue when packing or unpacking a bitfield with unnamed fields AND
-
caterpillar.abc
- Add
_SupportsBitsprotocol. - Add
_ContainsBitsprotocol. - Add
_SupportsTypeprotocol.
- Add
-
caterpillar.shortcuts
- Add new shortcuts:
typeof,to_struct,hasstruct,getstruct, andsizeof.
- Add new shortcuts:
-
caterpillar.shared
- Add new constants from other modules:
ATTR_BYTEORDER,ATTR_TYPE,ATTR_BITS,ATTR_SIGNED,ATTR_TEMPLATE.
- Add new constants from other modules:
-
caterpillar.context
- Add context attribute
_rootto point to the root context instance. Internal parent iteration now usesself.get(...).
- Add context attribute
-
caterpillar.abc
- Remove
_Actionprotocol; split into_ActionLike = _SupportsActionUnpack | _SupportsActionPack. - Remove
__type__requirement from_StructLike. - Breaking: Remove
_EnumLikeand_ContextPathStr.
- Remove
-
caterpillar.model
- Remove unused
getformatfunction.
- Remove unused
-
caterpillar.fields.common
- Remove unused
__fmt__function inTransformer.
- Remove unused
-
caterpillar.abc
- Rename
_Switchprotocol to_SwitchLike. - Move
STRUCT_FIELDtocaterpillar.sharedasATTR_STRUCT; movehasstruct,getstruct, andtypeoftocaterpillar.shared.
- Rename
-
caterpillar.byteorder
- Move
BYTEORDER_FIELDtocaterpillar.sharedasATTR_BYTEORDER.
- Move
-
caterpillar.model
- Update
sizeofto check if the object implements_SupportsSizeprotocol. - Renew
Bitfieldconcept with enhanced syntax.
- Update
-
Documentation
- Update reference and library docs; improve section numbering.
- caterpillar.model
- Fix parsing of union objects with an unbound stream.
- Fix field options in Sequences and Structs not being populated when creating fields.