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
Sequenceclass 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_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.