implement sync-encode