Encoding function implement.