Implement textEncode and textDecode functions