Scanner
StateScanner(patterns, first_state, engine=None)
¶
Bases: Generic[S]
Single-pass scanner for state transitions.
This class orchestrates the scanning of a byte buffer or file
to identify transitions between different states based on predefined
patterns. It uses a ScanEngine to perform the actual pattern matching.
Type variables
S: An Enum type representing the possible states a file can be in.
Initializes the StateScanner.
| PARAMETER | DESCRIPTION |
|---|---|
|
A dictionary where keys are state Enum members and values are lists of byte patterns (regex or literal) that signify a transition to that state.
TYPE:
|
|
The initial state of the file, which is used to begin the scanning process.
TYPE:
|
|
An optional
TYPE:
|
engine = engine
¶
first_state = first_state
¶
patterns
¶
Returns the compiled patterns used by the internal scan engine.
This property provides access to the patterns that the scanner is configured to detect.
| RETURNS | DESCRIPTION |
|---|---|
|
The underlying patterns from the scan engine. |
scan(buf)
¶
Single-pass scan of bytes to identify states and their transitions.
This method iterates through the provided byte buffer, identifying
all occurrences of predefined patterns that indicate a change in state.
It constructs a list of StateTransition objects, each detailing
the from_state, to_state, and byte start_pos/end_pos of
each identified region.
| PARAMETER | DESCRIPTION |
|---|---|
|
The byte buffer to be scanned for state transitions.
TYPE:
|
| RETURNS | DESCRIPTION |
|---|---|
list[StateTransition]
|
A list of |