In the following code, when the end byte is checked, no byte is read. The first if is verified with the last information byte, and the second if is immediately verified without read any byte. Therefore, if the last byte doesn't match with the end byte, the parse function will return false and the read will fail
// strip off the data
if ((_parserState-1) < _payloadSize) {
_payload[_parserState-1] = _curByte;
_parserState++;
}
// check the end byte
if ((_parserState-1) == _payloadSize) {
if ((_curByte == _sbusFooter) || ((_curByte & _sbus2Mask) == _sbus2Footer)) {
_parserState = 0;
return true;
} else {
_parserState = 0;
return false;
}
}
In the following code, when the end byte is checked, no byte is read. The first if is verified with the last information byte, and the second if is immediately verified without read any byte. Therefore, if the last byte doesn't match with the end byte, the parse function will return false and the read will fail