class FFI::Pointer
Public Instance Methods
read_string_dn(max=0)
click to toggle source
Enhancement to FFI::Pointer
to be able to read a double-null terminated string, which would be returned e.g. by RfcGetVersion() in the SDK See stackoverflow.com/questions/9293307/ruby-ffi-ruby-1-8-reading-utf-16le-encoded-strings It should be safe to call this on a Pointer
within the context of the NW RFC SDK library, because all strings are supposed to be UTF-16LE encoded and double-null terminated
# File lib/nwrfc/nwrfclib.rb, line 37 def read_string_dn(max=0) cont_nullcount = 0 offset = 0 until cont_nullcount == 2 byte = get_bytes(offset, 1) cont_nullcount += 1 if byte == "\000" cont_nullcount = 0 if byte != "\000" offset += 1 end get_bytes(0, offset+1) end