RxCookbook icon indicating copy to clipboard operation
RxCookbook copied to clipboard

Stream of bytes/frames to Messages

Open LeeCampbell opened this issue 8 years ago • 1 comments

This question in SO (http://stackoverflow.com/questions/37687605/rx-net-message-parser) asks a very valid question of how do I parse some stream of bytes into messages based on a set of rules. The rules however require knowledge of where you are in parsing logic

  • are you in the header, the body or in between messages?
  • was the previous byte and escape/control character?
  • if you are in the body, was the previous byte that is a control character itself escaped?

Thus basic Rx operators are not enough. You can get so far with Buffer(2,1) but it fails in some edge cases.

It would be good to really clean up the example into a recipe. Perhaps using Stateless as the state machine?

LeeCampbell avatar Jun 08 '16 10:06 LeeCampbell

I imagine that this code could be generalised for use in transforming things like a WebSockets stream into a stream of JSON or strongly type objects.

LeeCampbell avatar Jun 08 '16 10:06 LeeCampbell