Skip to content

Conversation

@ecarjat
Copy link

@ecarjat ecarjat commented Dec 21, 2025

Summary

  • This change replaces blocking direct Stream reads with an internal RX ring buffer and non-blocking helpers, making BinaryIO tolerant of fragmented/partial frames and avoiding buffer overruns. Packet parsing now always resynchronizes to MARKER_BYTE, validates payload sizes, and defers incomplete payloads using a _pending state until the full payload arrives. Multi-byte primitive reads use safe assembly (memcpy) and <string.h> is included.

Changelog

  • Added: RX ring buffer and helpers (_rx_fill(), _rx_available(), _rx_peek(), _rx_read()) in BinaryIO.h and implemented in BinaryIO.cpp.
  • Changed: operator>> for float, uint32_t, and uint8_t to consume only available bytes and decrement remaining by actual bytes read.
  • Changed: Packet parsing to always resync to MARKER_BYTE, discard pre-marker bytes, safely read size/type, and handle incomplete payloads by setting _pending (_pending_type, _pending_payload) until the full payload is buffered.
  • Added: BINARYIO_RX_BUFFER_SIZE default and checks to reject frames whose payload would exceed buffer capacity (drops out-of-sync on overflow).
  • Safety: Use of memcpy and inclusion of <string.h> for reliable multi-byte assembly.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant