Implement encoding.