MCPcopy Create free account
hub / github.com/andreasfertig/programming-with-cpp20 / Parse

Function Parse

02.10-coroutineParsingDataStream0/main.cpp:191–219  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

189
190
191FSM 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
222generator<byte> sender(std::vector<byte> fakeBytes)

Callers 1

mainFunction · 0.70

Calls

no outgoing calls

Tested by

no test coverage detected