implement semantic encode