encoding and decoding of messages according to their payloads