4.5.1. Sequence#

class caterpillar.model.Sequence(model: _SeqModelT, order: _EndianLike | None = None, arch: _ArchLike | None = None, options: Iterable[_OptionLike] | None = None, field_options: Iterable[_OptionLike] | None = None)[source]#

Default implementation for a sequence of fields.

The native Python type mapped to this struct class is dict. To convert a dictionary into a sequence, you can either use the contructor directly or apply the type converter for this class:

>>> to_struct({'a': uint8})
Sequence(fields=['a'])

Changed in version 2.6.0: The Sequence class now internally uses another class (_Member) to store the fields and actions.

has_option(option: _OptionLike[Any]) bool[source]#

Check if the struct has a specific option.

Parameters:

option – The option to check.

Returns:

True if the struct has the specified option, else False.

_included(name: str, default: object, annotation: str | bytes | Field | type | _SupportsActionPack | _SupportsActionUnpack | Any) bool[source]#

Check if a field with the given name should be included.

Parameters:
  • name – The name of the field.

  • default – The default value of the field.

Returns:

True if the field should be included, else False.

_process_model() None[source]#

Process all fields in the model.

_process_field(name: str, annotation: object, default: object) Field[source]#

Process a field in the model.

Parameters:
  • name – The name of the field.

  • annotation – The annotation of the field.

  • default – The default value of the field.

Returns:

The processed field.

add_field(name: str, field: Field, included: bool = False) None[source]#

Add a field to the struct.

Parameters:
  • name – The name of the field.

  • field – The field to add.

  • included – True if the field should be included, else False.

add_action(action: _SupportsActionPack | _SupportsActionUnpack) None[source]#

Add an action to the struct.

Parameters:

action – The action to add.

del_field(name: str, field: Field) None[source]#

Remomves a field from this struct.

Parameters:
  • name – The name of the field.

  • field – The field to remove.