Module: Caf::Chunk::Helper

Includes:
Flt
Included in:
Caf::Chunk
Defined in:
lib/caf/chunk/helper.rb

Constant Summary collapse

BIT_SHIFTS_8 =
[64, 56, 48, 40, 32, 24, 16, 8]

Class Method Summary collapse

Class Method Details

.read_bytes(number, data, offset = 0) ⇒ Object



10
11
12
13
14
15
16
17
# File 'lib/caf/chunk/helper.rb', line 10

def self.read_bytes(number, data, offset = 0)
  buffer = 0
  number_minus = number - 1
  number_minus.downto(0) do |i|
    buffer += (data.getbyte(offset + number_minus - i) << (8 * i))
  end
  buffer
end

.read_chars(number, data, offset = 0) ⇒ Object



19
20
21
22
23
# File 'lib/caf/chunk/helper.rb', line 19

def self.read_chars(number, data, offset = 0)
  buffer = ''
  0.upto(number-1) { |i| buffer += data.getbyte(offset+i).chr }
  buffer
end

.read_double(data, offset = 0) ⇒ Object



25
26
27
28
29
# File 'lib/caf/chunk/helper.rb', line 25

def self.read_double(data, offset = 0)
  num = read_bytes(8, data, offset)
#      IEEE_binary64.from_bits_integer(num).to_number(Float)
  IEEE_DOUBLE.from_bits(num).convert_to(Float)
end

.read_int(data, offset = 0) ⇒ Object



31
32
33
# File 'lib/caf/chunk/helper.rb', line 31

def self.read_int(data, offset = 0)
  read_bytes(4, data, offset).to_i
end