Encode codec before writing to transport.

Handles when codec is Unicode.