Encodes and Decodes messages