Class: Caf::Chunk::Data

Inherits:
Base
  • Object
show all
Defined in:
lib/caf/chunk/data.rb

Instance Attribute Summary collapse

Attributes inherited from Base

#chunk_size, #chunk_type

Instance Method Summary collapse

Methods inherited from Base

#check_type_and_size, implements

Constructor Details

#initialize(chunk_header) ⇒ Data

Returns a new instance of Data.



14
15
16
# File 'lib/caf/chunk/data.rb', line 14

def initialize(chunk_header)
  super chunk_header
end

Instance Attribute Details

#edit_countObject

Returns the value of attribute edit_count.



12
13
14
# File 'lib/caf/chunk/data.rb', line 12

def edit_count
  @edit_count
end

#positionObject

Returns the value of attribute position.



12
13
14
# File 'lib/caf/chunk/data.rb', line 12

def position
  @position
end

#sizeObject

Returns the value of attribute size.



12
13
14
# File 'lib/caf/chunk/data.rb', line 12

def size
  @size
end

Instance Method Details

#fields_sizeObject

Raises:



28
29
30
# File 'lib/caf/chunk/data.rb', line 28

def fields_size
  raise(Caf::Error, "not implemented")
end

#read_data(file) ⇒ Object



32
33
34
35
36
37
38
39
40
41
42
43
44
# File 'lib/caf/chunk/data.rb', line 32

def read_data(file)
  edit = file.read(4)
  @edit_count = (edit.getbyte(0) << 32) + (edit.getbyte(1) << 16) + (edit.getbyte(2) << 8) + edit.getbyte(3)
  @position = file.pos
  unless chunk_size == -1
    @size = chunk_size - 4  # 4 bytes are from edit_count field
    file.seek(@size, IO::SEEK_CUR)
  else
    file.seek(0, IO::SEEK_END)
    @size = file.pos - @position
    # TODO should update chunk_size field with @size + 4 if file is writable
  end
end

#to_sObject



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

def to_s
  "#{chunk_type} (data chunk):\n"+
    " -edit count:         #{edit_count}\n" +
    " -data size:          #{size}\n" +
    " -data position:      #{position}\n"
end

#validateObject



25
26
# File 'lib/caf/chunk/data.rb', line 25

def validate
end