implemented encode for Message codec