class BMFF::Box::Base

Attributes

raw_data[RW]

Public Instance Methods

compose(data) click to toggle source
# File lib/bmffglitch/bmffex.rb, line 15
def compose(data)
  # size(uint32) + type(uint32)
  size = 4 + 4
  if @type == 'uuid'
    # extended_type(uint8[16])
    size += 16
  end
  # 8 is the size of largesize(uint64)
  if size + 8 + data.length > 0xffffffff
    largesize = size + 8 + data.length 
    size = 1
  else
    size += data.length
  end
  
  sio = StringIO.new("", "r+")
  sio.set_encoding("ascii-8bit")
  sio.extend(BMFF::BinaryAccessor)
  
  sio.write_uint32(size)
  sio.write_ascii(@type)
  sio.write_uint64(largesize) if size == 1
  sio.write_uuid(@usertype) if @type == 'uuid'
  return sio.string + data
end
parse_data() click to toggle source
# File lib/bmffglitch/bmffex.rb, line 41
def parse_data
  data_start_pos = @io.pos
  seek_to_end
  data_end_pos = @io.pos
  @io.pos = data_start_pos
  @raw_data = @io.read(data_end_pos - data_start_pos)
  @io.pos = data_start_pos
end
to_s() click to toggle source
# File lib/bmffglitch/bmffex.rb, line 50
def to_s
  if container?
    compose(@children.map {|box| box.to_s}.join)
  else
    compose(@raw_data)
  end
end