Byte stuffing like in https://datatracker.ietf.org/doc/html/rfc1662#section-4.2 except that we use a long byte prefix to make it easier to find and less chance of constantly escaping every random 255th byte
Pick some 7 bytes prefix P, something less likely to occur in erlang term_to_binary or utf8 encodings.
P = f5, f6, f7, f8, f9, fa, fb
One byte H (=fc) is the header byte. The header tag: P|H = f5, f6, f7, f8, f9, fa, fb, fc
Another X (=fd) is the escape header byte. The whole escape prefix is P|X = f5, f6, f7, f8, f9, fa, fb, fd
Encoding a non-header region:
P|H -> P|X|HP|X -> P|X|X
We never have a raw P|H in a non-header by construction
Decoding (from file, read backwards in overlapping windows):
P|H-> headerP|X|H->P|Hun-escapedP|X|X->P|Xun-escaped