I'm currently trying to write a parser for an ASCII text file that is surrounded by a small envelope with a checksum.
Basic file structure: <0x02> <"File payload"> <0x03> <16bit CRC>
and I want to extract the payload on another line to the next parser.
The parser expression that I use to parse this shell looks like this:
qi::phrase_parse( first, last, char_('\x02') >> *print >> char_('\x02') >> *xdigit, space );
The input is being consumed ... and I already tried to dump the payload:
qi::phrase_parse( first, last, char_('\x02') >> *print[cout << _1] >> char_('\x02') >> *xdigit, space );
But the problem is that every new line, space, etc. omitted!
Now my questions are:
How to extract contents between bytes 0x02 / 0x03 (ETX / STX) correctly, without omitting spaces, newlines, etc.
And my approach is to remove the envelope first and then parse the payload is good or is there another better approach I should use?
fhw72 source share