Class: FFI::Pointer
- Inherits:
-
Object
- Object
- FFI::Pointer
- Defined in:
- lib/nwrfc/nwrfclib.rb
Instance Method Summary collapse
-
#read_string_dn(max = 0) ⇒ Object
Enhancement to FFI::Pointer to be able to read a double-null terminated string, which would be returned e.g.
Instance Method Details
#read_string_dn(max = 0) ⇒ Object
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
33 34 35 36 37 38 39 40 41 42 43 |
# File 'lib/nwrfc/nwrfclib.rb', line 33 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 |