Handshake preamble match
Your task
A serial capture tool checks that every log a device sends opens with the handshake preamble its firmware promises. The preamble is matched from the very first character of the stream, never from further along. A '?' in the preamble stands for one character the firmware is free to pick, a revision byte for instance, so it accepts whatever the stream holds in that spot. A '?' in the stream is an ordinary character with no special meaning. Given stream and preamble, return the index of the first position where the stream stops following the preamble. When the stream runs out before the preamble is finished, that position is the length of the stream. Return -1 when the whole preamble is followed, even when the stream carries on well past it. Anything follows an empty preamble.
Examples
preamble_break_index(stream: str, preamble: str) -> intpreamble_break_index("AB12-READY", "AB??-")-1preamble_break_index("AB12*READY", "AB??-")4preamble_break_index("AB1", "AB??")3