
1. wait for a character;

2. when one becomes available, read it;

3a. if that completes a message, handle the message;
3b. if it doesn't complete a message, repeat from (1);

4. repeat as necessary.