Class: PackedBitObject

Inherits:
Object
  • Object
show all
Defined in:
lib/swf_file/packed_bit_object.rb

Overview

TODO: Needs refactoring & cleanup

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(bitMarker, byteMarker, decimalValue) ⇒ PackedBitObject

Returns a new instance of PackedBitObject.



6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
# File 'lib/swf_file/packed_bit_object.rb', line 6

def initialize(bitMarker,byteMarker,decimalValue)
  @bitIndex = bitMarker;
  @byteIndex = byteMarker;
  @value = decimalValue;
  @nextBitIndex = bitMarker;
  if ( bitMarker <= 7 )
    @nextBitIndex+=1
    @nextByteIndex =byteMarker
    @nextByteBoundary = (byteMarker+=1)
  else
    @nextBitIndex = 0
    @nextByteIndex+=1
    @nextByteBoundary = @nextByteIndex;
  end
end

Instance Attribute Details

#bitIndexObject

Returns the value of attribute bitIndex.



4
5
6
# File 'lib/swf_file/packed_bit_object.rb', line 4

def bitIndex
  @bitIndex
end

#byteIndexObject

Returns the value of attribute byteIndex.



4
5
6
# File 'lib/swf_file/packed_bit_object.rb', line 4

def byteIndex
  @byteIndex
end

#nextBitIndexObject

Returns the value of attribute nextBitIndex.



4
5
6
# File 'lib/swf_file/packed_bit_object.rb', line 4

def nextBitIndex
  @nextBitIndex
end

#nextByteBoundaryObject

Returns the value of attribute nextByteBoundary.



4
5
6
# File 'lib/swf_file/packed_bit_object.rb', line 4

def nextByteBoundary
  @nextByteBoundary
end

#nextByteIndexObject

Returns the value of attribute nextByteIndex.



4
5
6
# File 'lib/swf_file/packed_bit_object.rb', line 4

def nextByteIndex
  @nextByteIndex
end

#valueObject

Returns the value of attribute value.



4
5
6
# File 'lib/swf_file/packed_bit_object.rb', line 4

def value
  @value
end

Class Method Details

.from_packed_bits(bytes, byte_marker, bit_marker, length) {|pbo| ... } ⇒ Object

Yields:

  • (pbo)


22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
# File 'lib/swf_file/packed_bit_object.rb', line 22

def self.from_packed_bits(bytes, byte_marker, bit_marker, length)
  total = 0
  shift = 7 - bit_marker 
  counter = 0 
  bit_index = bit_marker 
  byte_index = byte_marker 

  while counter<length
    (bit_marker...8).each do |i|
      bit =((bytes[byte_marker].ord & 0xff ) >> shift ) & 1
      total = ( total << 1 ) + bit
      bit_index = i
      shift-=1
      counter+=1

      if counter==length
        break
      end
    end

    byte_index = byte_marker
    byte_marker+=1
    bit_marker = 0
    shift = 7
  end

  pbo = PackedBitObject.new(bit_index, byte_index, total)
  
  yield pbo if block_given?
  
  pbo
end