Class: Nitro::OvtBin

Inherits:
Object
  • Object
show all
Includes:
NitroBind
Defined in:
lib/nitro/nitro.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(args = {}) ⇒ OvtBin

Returns a new instance of OvtBin.



115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
# File 'lib/nitro/nitro.rb', line 115

def initialize(args = {})
  if args.has_key? :file_path
    bin = File.binread(args[:file_path])
    @size = bin.bytesize
    @ptr = FFI::MemoryPointer.new(:uint8, @size)
    @ptr.put_bytes(0, bin)

  elsif args.has_key?(:ptr) && args.has_key?(:size)
    @ptr = args[:ptr]
    @size = args[:size]
    @entry_count = @size / OvtEntry.size
  else
    raise ArgumentError
  end
end

Instance Attribute Details

#entry_countObject (readonly)

Returns the value of attribute entry_count.



113
114
115
# File 'lib/nitro/nitro.rb', line 113

def entry_count
  @entry_count
end

#sizeObject (readonly)

Returns the value of attribute size.



113
114
115
# File 'lib/nitro/nitro.rb', line 113

def size
  @size
end

Instance Method Details

#get_entry(id) ⇒ Object

Raises:

  • (IndexError)


131
132
133
134
# File 'lib/nitro/nitro.rb', line 131

def get_entry(id)
  raise IndexError if id > @entry_count-1
  OvtEntry.new(@ptr + id*OvtEntry.size)
end