add a message entity and use it in the client

I think the 4 casting may be a little overkill, as you test and return Exceptions if your values aren't the type you want.