Class: Furnace::SWF::TagWrapper

Inherits:
BinData::Record
  • Object
show all
Defined in:
lib/furnace-swf/swf/tag_wrapper.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Instance Attribute Details

#contentObject

Returns the value of attribute content.



8
9
10
# File 'lib/furnace-swf/swf/tag_wrapper.rb', line 8

def content
  @content
end

Instance Method Details

#content_sizeObject



77
78
79
80
81
82
83
# File 'lib/furnace-swf/swf/tag_wrapper.rb', line 77

def content_size
  if @content.is_a? Tag
    @content.num_bytes
  else
    @content.length
  end
end

#debug_name_of(child) ⇒ Object



85
86
87
88
89
90
91
# File 'lib/furnace-swf/swf/tag_wrapper.rb', line 85

def debug_name_of(child)
  if child.is_a?(Tag)
    "#{debug_name}.content"
  else
    super
  end
end

#do_num_bytesObject



71
72
73
74
75
# File 'lib/furnace-swf/swf/tag_wrapper.rb', line 71

def do_num_bytes
  self.real_length = content_size

  super
end

#do_read(io) ⇒ Object

Nested reads/writes.



44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
# File 'lib/furnace-swf/swf/tag_wrapper.rb', line 44

def do_read(io)
  super

  orig_offset = io.offset

  if Tag.exists_for?(type)
    @content  = Tag.instantiate(type, self, parent)
    @content.do_read io

    if io.offset - orig_offset != real_length
      raise "Invalid tag #{@content}"
    end
  else
    @content  = io.readbytes(real_length)
  end
end

#do_write(io) ⇒ Object



61
62
63
64
65
66
67
68
69
# File 'lib/furnace-swf/swf/tag_wrapper.rb', line 61

def do_write(io)
  super

  if Tag.exists_for?(type)
    @content.do_write io
  else
    io.writebytes @content
  end
end

#real_lengthObject



28
29
30
# File 'lib/furnace-swf/swf/tag_wrapper.rb', line 28

def real_length
  short_length == 0x3f ? long_length : short_length
end

#real_length=(value) ⇒ Object



32
33
34
35
36
37
38
39
40
# File 'lib/furnace-swf/swf/tag_wrapper.rb', line 32

def real_length=(value)
  if value >= 0x3f
    self.short_length = 0x3f
    self.long_length  = value
  else
    self.short_length = value
    self.long_length  = 0
  end
end

#short_lengthObject



20
21
22
# File 'lib/furnace-swf/swf/tag_wrapper.rb', line 20

def short_length
  type_and_length & 0x3f
end

#short_length=(value) ⇒ Object



24
25
26
# File 'lib/furnace-swf/swf/tag_wrapper.rb', line 24

def short_length=(value)
  self.type_and_length = (type_and_length & 0xfffc) | (value & 0x3f)
end

#typeObject

Accessors for braindead format.



12
13
14
# File 'lib/furnace-swf/swf/tag_wrapper.rb', line 12

def type
  type_and_length >> 6
end

#type=(value) ⇒ Object



16
17
18
# File 'lib/furnace-swf/swf/tag_wrapper.rb', line 16

def type=(value)
  self.type_and_length = (type_and_length & 0x3f) | (value << 6)
end