decode and encode messages