encode string data when it's written