|
BCNP 3.2.1
Batched Command Network Protocol
|
Parses a byte stream into BCNP packets. More...
#include <stream_parser.h>
Classes | |
| struct | ErrorInfo |
Public Types | |
| using | PacketCallback = std::function<void(const PacketView&)> |
| using | ErrorCallback = std::function<void(const ErrorInfo&)> |
| using | WireSizeLookup = std::function<std::size_t(MessageTypeId)> |
Public Member Functions | |
| StreamParser (PacketCallback onPacket, ErrorCallback onError={}, std::size_t bufferSize=4096) | |
| Construct a stream parser with callbacks and buffer size. | |
| void | Push (const uint8_t *data, std::size_t length) |
| Push raw bytes into the parser for processing. | |
| void | Reset (bool resetErrorState=true) |
| Reset the parser to its initial state. | |
| void | SetWireSizeLookup (WireSizeLookup lookup) |
| Set custom wire size lookup (for testing with custom message types) | |
Static Public Attributes | |
| static constexpr std::size_t | kMaxParseIterationsPerPush = 1024 |
Parses a byte stream into BCNP packets.
Handles stream reassembly, framing, CRC validation, and error recovery. Uses a ring buffer internally for efficient parsing of partial packets.
Thread-safety: Not thread-safe. Caller must synchronize access.
Definition at line 21 of file stream_parser.h.
| using bcnp::StreamParser::ErrorCallback = std::function<void(const ErrorInfo&)> |
Definition at line 29 of file stream_parser.h.
| using bcnp::StreamParser::PacketCallback = std::function<void(const PacketView&)> |
Definition at line 23 of file stream_parser.h.
| using bcnp::StreamParser::WireSizeLookup = std::function<std::size_t(MessageTypeId)> |
Callback to get wire size for a message type ID Return 0 if message type is unknown
Definition at line 33 of file stream_parser.h.
| bcnp::StreamParser::StreamParser | ( | PacketCallback | onPacket, |
| ErrorCallback | onError = {}, | ||
| std::size_t | bufferSize = 4096 ) |
Construct a stream parser with callbacks and buffer size.
| onPacket | Callback invoked for each valid packet |
| onError | Callback invoked on parse errors (optional) |
| bufferSize | Internal ring buffer size (minimum: header + checksum) |
Definition at line 24 of file stream_parser.cpp.
| void bcnp::StreamParser::Push | ( | const uint8_t * | data, |
| std::size_t | length ) |
Push raw bytes into the parser for processing.
Bytes are added to the internal ring buffer and parsed for complete packets. Valid packets trigger the onPacket callback; parse errors trigger onError. The parser handles partial packets across multiple Push() calls.
| data | Pointer to incoming byte data |
| length | Number of bytes to process |
Definition at line 46 of file stream_parser.cpp.
| void bcnp::StreamParser::Reset | ( | bool | resetErrorState = true | ) |
Reset the parser to its initial state.
Clears the internal buffer and optionally resets error tracking. Call this when starting a new connection or after unrecoverable errors.
| resetErrorState | If true, also resets consecutive error count and stream offset |
Definition at line 100 of file stream_parser.cpp.
|
inline |
Set custom wire size lookup (for testing with custom message types)
Definition at line 42 of file stream_parser.h.
|
staticconstexpr |
Definition at line 44 of file stream_parser.h.