Class: PackedBitObject
- Inherits:
-
Object
- Object
- PackedBitObject
- Defined in:
- lib/swf_file/packed_bit_object.rb
Overview
TODO: Needs refactoring & cleanup
Instance Attribute Summary collapse
-
#bitIndex ⇒ Object
Returns the value of attribute bitIndex.
-
#byteIndex ⇒ Object
Returns the value of attribute byteIndex.
-
#nextBitIndex ⇒ Object
Returns the value of attribute nextBitIndex.
-
#nextByteBoundary ⇒ Object
Returns the value of attribute nextByteBoundary.
-
#nextByteIndex ⇒ Object
Returns the value of attribute nextByteIndex.
-
#value ⇒ Object
Returns the value of attribute value.
Class Method Summary collapse
Instance Method Summary collapse
-
#initialize(bitMarker, byteMarker, decimalValue) ⇒ PackedBitObject
constructor
A new instance of PackedBitObject.
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
#bitIndex ⇒ Object
Returns the value of attribute bitIndex.
4 5 6 |
# File 'lib/swf_file/packed_bit_object.rb', line 4 def bitIndex @bitIndex end |
#byteIndex ⇒ Object
Returns the value of attribute byteIndex.
4 5 6 |
# File 'lib/swf_file/packed_bit_object.rb', line 4 def byteIndex @byteIndex end |
#nextBitIndex ⇒ Object
Returns the value of attribute nextBitIndex.
4 5 6 |
# File 'lib/swf_file/packed_bit_object.rb', line 4 def nextBitIndex @nextBitIndex end |
#nextByteBoundary ⇒ Object
Returns the value of attribute nextByteBoundary.
4 5 6 |
# File 'lib/swf_file/packed_bit_object.rb', line 4 def nextByteBoundary @nextByteBoundary end |
#nextByteIndex ⇒ Object
Returns the value of attribute nextByteIndex.
4 5 6 |
# File 'lib/swf_file/packed_bit_object.rb', line 4 def nextByteIndex @nextByteIndex end |
#value ⇒ Object
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
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 |