Skip to content

Sync Pattern - state machine #38

@Inczert

Description

@Inczert

A sync pattern state machine should be defined to address the packets validity.

i.e.
State machine approach (forward-only, O(N))

State A: SEEK_SYNC
Run a rolling matcher over incoming bytes.
When sync matched, go to READ_HEADER.
State B: READ_HEADER (6 bytes)
Read 6 bytes.
Validate:
version == 0
length <= max_allowed
(optional) APID is in expected range / whitelist
Compute expected_remaining = 1 + packet_length (bytes after primary header)
Go to SKIP_REMAINING.
State C: SKIP_REMAINING
Consume expected_remaining bytes.
While consuming, continue rolling sync matcher.
If sync appears early (before counter hits 0):
treat it as possible resync
increment “early-sync” metric
immediately switch to READ_HEADER from that sync position only if the next header passes sanity checks (see below)
When counter hits 0:
you are at boundary, expect next sync (in strict mode)
switch back to SEEK_SYNC and wait for sync

Metadata

Metadata

Assignees

Labels

enhancementNew feature or request

Projects

Status

Todo

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions