This parallels encode_utf8 which we already had. Decoding is more fraught with perils than encoding, so I've also included a small test program.