How to (pointer).read_string given the offset in an ffi struct?

28 views
Skip to first unread message

cootcraig

unread,
Aug 21, 2015, 3:13:09 PM8/21/15
to ruby-ffi
Suppose I have an ffi struct like this:

class RAW_BUF < FFI::Struct
  layout :data, [:uchar, 576]
end

How would I construct a pointer to offset 124 (for example)
in the struct?

I was hoping to use pointer.read_string where the pointer
is constructed as above.


cootcraig

unread,
Aug 22, 2015, 1:47:06 AM8/22/15
to ruby-ffi
I figured out a solution. See this function

  def pointer_from_struct_offset(ffi_struct,offset)
    FFI::Pointer.new(ffi_struct.to_ptr.address + offset)
  end
 
Reply all
Reply to author
Forward
0 new messages