kevinmehall/rust-peg

How to use peg for streams of data - or how to implemented streaming in peg

torfmaster opened this issue · 0 comments

Hi,

first of all let me thank you for your wonderful library. It saved me days of implementation (and lots of pain) for implementing a parser for a proprietary binary protocol.

I was wondering what it would take to use peg for streams of data. I am receiving a stream of potentially incomplete or corrupt data and I am interested in only the valid parts of that stream. Currently, I have implemented a very rudimentary parser for my protocol to detect beginning and end of a message (though quite erroneous). My questions are

  • How can I use peg to filter out only the interesting parts of the stream? I can only speculate, but probably it would make sense to look at the location where errors occur to decide what to do (e.g. move on because error is in the end, skip these bytes because error is at the beginning, read more data because error is in the middle).
  • What would it take to extend the api of peg to support streaming?

I am very interested about your thoughts. Btw the project I am working on is located here: https://github.com/torfmaster/hackdose-sml-parser.

Thank you!