Abstract base classes#

Struct#

class caterpillar.abc._SupportsPack(*args, **kwargs)[source]#

An abstract base class for objects that support packing data into a binary stream.

class caterpillar.abc._SupportsUnpack(*args, **kwargs)[source]#

An abstract base class for objects that support unpacking data from a binary stream.

class caterpillar.abc._SupportsSize(*args, **kwargs)[source]#

An abstract base class for objects that support determining the size of packed data.

class caterpillar.abc._StructLike(*args, **kwargs)[source]#

An abstract base class for struct-like objects that can be packed, unpacked, and have a size.

class caterpillar.abc._ContainsStruct(*args, **kwargs)[source]#

An abstract base class indicating that a class contains a _StructLike object.

Context#

class caterpillar.abc._ContextLike(*args, **kwargs)[source]#

A dictionary-like object used as a context for packing and unpacking.

It allows direct attribute access and modification.

class caterpillar.abc._ContextLambda(*args, **kwargs)[source]#

An abstract base class for a lambda function that takes a _ContextLike object as an argument.

Other base classes#

class caterpillar.abc._EnumLike(*args, **kwargs)[source]#

An abstract base class for enum-like objects with a value, name, and mappings.

class caterpillar.abc._Switch(*args, **kwargs)[source]#

An abstract base class for a switch-like object that generates a _StructLike based on a value and context.

Standard interface#

abc.STRUCT_FIELD = '__struct__'#
caterpillar.abc.hasstruct(obj: Any) bool[source]#

Check if the given object has a structure attribute.

Parameters:

obj – The object to check.

Returns:

True if the object has a structure attribute, else False.

caterpillar.abc.getstruct(obj: Any, /, __default: Any = None) _StructLike | None[source]#

Get the structure attribute of the given object.

Parameters:

obj – The object to get the structure attribute from.

Returns:

The structure attribute of the object.

caterpillar.abc.typeof(struct: _StructLike | _ContainsStruct) object[source]#