Subject:
[ruby-ffi] FFI::StructLayout::CharArray and UTF-8 encoding
From:
Navaneeth KN
Date:
5/8/12 12:34 AM
To:
ruby-ffi@googlegroups.com

Hello,

I have a struct which has character arrays which contains UTF8 encoded string. My C library ensures it always works with UTF8 for input and output. I wrapped the C library in ruby using FFI. When reading these values from  FFI using FFI::StructLayout::CharArray.read_string gives me a ruby string with encoding ASCII-8BIT. When I try to convert this into UTF-8 using,

str.encode!("UTF-8")

it fails saying few characters can't be encoded to UTF8. I am wondering is there a way to tell FFI to treat strings as UTF-8 encoded?

Any help would be great

Thanks