add encoder test and fix encoder string write bug