hSetEncoding: change the encoding on both read and write sides (#4066)