decode and encode API