DDR-0031: E27 Framing Resynchronization Rule (STARTCHAR Followed by Non-Zero)

Status: Accepted
Date: 2025-01-xx

Context
-------
The E27 protocol framing layer must remain resilient to:

- TCP segmentation
- Corrupted frames
- Partial frames
- Garbage bytes injected into the stream

Node-RED reference implementations apply a specific resynchronization rule not explicitly documented in early protocol descriptions.

Decision
--------
The deframer SHALL implement the following rule:

- If STARTCHAR (0x7E) is encountered:
  - Followed by 0x00: represents an escaped literal STARTCHAR in payload
  - Followed by any non-zero byte: ALWAYS indicates the start of a new frame

In the resync case:
- The byte following STARTCHAR is treated as the protocol byte
- Any partially accumulated frame is abandoned
- Deframing restarts immediately from the new protocol byte

CRC errors MUST NOT halt stream processing; the deframer must continue scanning for the next valid frame.

Consequences
------------
- Deframer must be stateful across TCP chunks
- CRC failures emit error results but do not stop parsing
- Frame recovery after corruption is guaranteed
- Behavior is deterministic and test-locked

Related
-------
- ADR-010x (E27 framing semantics)
- DDR-0028 (CRC and length-field semantics)
- Tests: test_e27_framing.py, test_e27_roundtrip.py
