Factored message parsing code from IO code.