decode and encode messages to be sent and recv