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



On Tuesday, 8 May 2012 11:04:49 UTC+5:30, Navaneeth KN wrote:
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 looks like str.force_encoding('UTF-8') works well. But I am still ineterested  to know if there are any FFI way of specifying the encoding.

Thanks