Separate framing and parsing

Handling framing in parser was fragile and lead to loss of
synchronization in the event of a mis-parse.