class FFI::Pointer
def self.size
-
(Numeric)
-
def self.size SIZE end unless respond_to?(:size)
def read(type)
-
(Object)
-
Parameters:
-
type
(Symbol, Type
) -- of data to read
def read(type) get(type, 0) end unless method_defined?(:read)
def read_array_of_type(type, reader, length)
-
(Array)
-
Parameters:
-
length
(Numeric
) -- -
reader
(Symbol
) -- method to send to +self+ to read +type+ -
type
(Type
) -- type of data to read from pointer's contents
def read_array_of_type(type, reader, length) ary = [] size = FFI.type_size(type) tmp = self length.times { |j| ary << tmp.send(reader) tmp += size unless j == length-1 # avoid OOB } ary end unless method_defined?(:read_array_of_type)
def read_string(len=nil)
-
(String)
-
Parameters:
-
len
(nil, Numeric
) -- length of string to return
def read_string(len=nil) if len return ''.b if len == 0 get_bytes(0, len) else get_string(0) end end unless method_defined?(:read_string)
def read_string_length(len)
-
(String)
-
Parameters:
-
len
(Numeric
) -- length of string to return
def read_string_length(len) get_bytes(0, len) end unless method_defined?(:read_string_length)
def read_string_to_null
-
(String)
-
def read_string_to_null get_string(0) end unless method_defined?(:read_string_to_null)
def to_ptr
-
(self)
-
def to_ptr self end unless method_defined?(:to_ptr)
def write(type, value)
-
(nil)
-
Parameters:
-
value
(Object
) -- to write -
type
(Symbol, Type
) -- of data to read
def write(type, value) put(type, 0, value) end unless method_defined?(:write)
def write_array_of_type(type, writer, ary)
-
(self)
-
Parameters:
-
ary
(Array
) -- -
writer
(Symbol
) -- method to send to +self+ to write +type+ -
type
(Type
) -- type of data to write to pointer's contents
def write_array_of_type(type, writer, ary) size = FFI.type_size(type) ary.each_with_index { |val, i| break unless i < self.size self.send(writer, i * size, val) } self end unless method_defined?(:write_array_of_type)
def write_string(str, len=nil)
-
(self)
-
Parameters:
-
len
(Numeric
) -- length of string to return -
str
(String
) -- string to write
def write_string(str, len=nil) len = str.bytesize unless len # Write the string data without NUL termination put_bytes(0, str, 0, len) end unless method_defined?(:write_string)
def write_string_length(str, len)
-
(self)
-
Parameters:
-
len
(Numeric
) -- length of string to return -
str
(String
) -- string to write
def write_string_length(str, len) put_bytes(0, str, 0, len) end unless method_defined?(:write_string_length)