LeeCampbell / RxCookbook

Collection of recipes and snippets helping you create useful Rx code
281 stars 39 forks source link

Stream of bytes/frames to Messages #34

Open LeeCampbell opened 8 years ago

LeeCampbell commented 8 years ago

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

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 commented 8 years ago

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.