Class: Omnizip::Algorithms::Zstandard::FSE::ForwardBitStream
- Inherits:
-
Object
- Object
- Omnizip::Algorithms::Zstandard::FSE::ForwardBitStream
- Defined in:
- lib/omnizip/algorithms/zstandard/fse/bitstream.rb
Overview
Forward bitstream reader (for Huffman decoding)
Reads bits in normal forward order from a starting position.
Instance Attribute Summary collapse
-
#bit_position ⇒ Integer
readonly
Current bit position.
-
#data ⇒ String
readonly
The compressed data.
Instance Method Summary collapse
-
#byte_position ⇒ Integer
Get current byte position.
-
#exhausted? ⇒ Boolean
Check if bitstream is exhausted.
-
#initialize(data, start_byte = 0) ⇒ ForwardBitStream
constructor
Initialize bitstream with data.
-
#read_bits(count) ⇒ Integer
Read bits from the stream (in forward order).
Constructor Details
#initialize(data, start_byte = 0) ⇒ ForwardBitStream
Initialize bitstream with data
129 130 131 132 |
# File 'lib/omnizip/algorithms/zstandard/fse/bitstream.rb', line 129 def initialize(data, start_byte = 0) @data = data.dup.force_encoding(Encoding::BINARY) @bit_position = start_byte * 8 end |
Instance Attribute Details
#bit_position ⇒ Integer (readonly)
Returns Current bit position.
123 124 125 |
# File 'lib/omnizip/algorithms/zstandard/fse/bitstream.rb', line 123 def bit_position @bit_position end |
#data ⇒ String (readonly)
Returns The compressed data.
120 121 122 |
# File 'lib/omnizip/algorithms/zstandard/fse/bitstream.rb', line 120 def data @data end |
Instance Method Details
#byte_position ⇒ Integer
Get current byte position
160 161 162 |
# File 'lib/omnizip/algorithms/zstandard/fse/bitstream.rb', line 160 def byte_position @bit_position / 8 end |
#exhausted? ⇒ Boolean
Check if bitstream is exhausted
153 154 155 |
# File 'lib/omnizip/algorithms/zstandard/fse/bitstream.rb', line 153 def exhausted? @bit_position >= @data.bytesize * 8 end |
#read_bits(count) ⇒ Integer
Read bits from the stream (in forward order)
Bits are read from MSB to LSB within each byte.
140 141 142 143 144 145 146 147 148 |
# File 'lib/omnizip/algorithms/zstandard/fse/bitstream.rb', line 140 def read_bits(count) return 0 if count.zero? result = 0 count.times do result = (result << 1) | read_single_bit end result end |