encode must not be called directly