Generalizes serial stream parser and adds a unit test.