| 189 | |
| 190 | |
| 191 | FSM Parse() |
| 192 | { |
| 193 | while(true) { |
| 194 | byte b = co_await byte{}; |
| 195 | if(ESC != b) { continue; } |
| 196 | |
| 197 | b = co_await byte{}; |
| 198 | if(SOF != b) { continue; } // #A not looking at a start sequence |
| 199 | |
| 200 | std::string frame{}; |
| 201 | while(true) { // #B capture the full frame |
| 202 | b = co_await byte{}; |
| 203 | |
| 204 | if(ESC == b) { |
| 205 | // #C skip this byte and look at the next one |
| 206 | b = co_await byte{}; |
| 207 | |
| 208 | if(SOF == b) { |
| 209 | co_yield frame; |
| 210 | break; |
| 211 | } else if(ESC != b) { // #D out of sync |
| 212 | break; |
| 213 | } |
| 214 | } |
| 215 | |
| 216 | frame += static_cast<char>(b); |
| 217 | } |
| 218 | } |
| 219 | } |
| 220 | |
| 221 | |
| 222 | generator<byte> sender(std::vector<byte> fakeBytes) |