Re-implement parser function

This gets rid of the MASSMESSAGE_PARSE hack, and makes
the parser function code more flexible.

Change-Id: I1ac472a763352c43d74c8fc96ed9d02095d27548
Add type hinting

Change-Id: I7de3a4de4e59a42a6c0c61aaddd7f8d7954aa233