Method: CTypes::Struct.offsetof

Defined in:
lib/ctypes/struct.rb

.offsetof(attr) ⇒ Integer

get the offset of a field within the structure in bytes

Parameters:

  • name of the attribute

Returns:

  • byte offset



267
268
269
270
271
272
273
274
# File 'lib/ctypes/struct.rb', line 267

def self.offsetof(attr)
  @offsets ||= @fields.inject([0, {}]) do |(offset, o), (key, type)|
    o[key] = offset
    [type.size ? offset + type.size : nil, o]
  end.last

  @offsets[attr]
end