Serial and COBS example
examples/serial_cobs/ shows how to carry predsync frames over a byte stream.
Serial ports have no message boundaries, so the host adds COBS framing with a
0x00 delimiter. COBS removes zero bytes from the payload and guarantees that
the delimiter occurs only between frames.
# deterministic in-memory round trip (CI gate)
cargo run -p predsync-serial-cobs-example -- self-test
# optional real port on a POSIX host (configured with stty)
cargo run -p predsync-serial-cobs-example -- send /dev/ttyUSB0 115200 10
cargo run -p predsync-serial-cobs-example -- receive /dev/ttyUSB0 115200 10
The in-memory test encodes predsync frames, applies COBS, appends the delimiter, decodes COBS, and feeds the recovered frame to the predsync decoder. The result must match the direct frame byte-for-byte and decode to the same values. Unit tests cover zero-byte handling, empty payloads, delimiter placement, truncation and malformed codes.
The real-port mode is optional because CI agents do not have a serial device and platform support varies. It opens the port with the requested baud rate, accumulates bytes until a delimiter, COBS-decodes one frame at a time, and prints decoded values with their validity flags. Its sender stops on Ctrl-C and prints median, mean and a 95% bootstrap confidence interval for predicted fields, byte savings and percentage size reduction. A maximum/mean message-size line precedes the overall figure. Savings are measured on predsync frame bytes before COBS framing; the baseline is a fresh encoder sending every true value at the same tick.
Framing is not part of the predsync wire format. A receiver must pass exactly
one complete frame to Decoder::feed; never concatenate frames or feed a partial
buffer.