Ref System
Ref
- class pystructs.ref.Ref(path: str)[source]
Bases:
objectReference to another field’s value.
Ref allows fields to reference other fields’ current values. This is used for variable-length fields and conditional logic.
- Path formats:
‘field_name’: Same level field
‘nested.field’: Nested struct field (dot notation)
‘../field_name’: Parent struct field
‘/header/size’: Absolute path from root
- Examples:
>>> payload = Bytes(size=Ref('payload_size')) >>> data = Bytes(size=Ref('header.data_size')) >>> item_data = Bytes(size=Ref('../item_size'))
RefComparison
RefLogical
- class pystructs.ref.RefLogical(left: RefComparison | RefLogical, op: str, right: RefComparison | RefLogical)[source]
Bases:
objectLogical combination of RefComparison objects.
- Examples:
>>> cond = (Ref('version') >= 2) & (Ref('flags') != 0) >>> field = Conditional(UInt32(), when=cond)