Class: Omnizip::Algorithms::Zstandard::FSE::Decoder
- Inherits:
-
Object
- Object
- Omnizip::Algorithms::Zstandard::FSE::Decoder
- Defined in:
- lib/omnizip/algorithms/zstandard/fse/table.rb
Overview
FSE Decoder (RFC 8878 Section 4.1)
Decodes symbols from FSE-encoded bitstreams.
Instance Attribute Summary collapse
-
#state ⇒ Integer
readonly
Current state.
-
#table ⇒ Table
readonly
FSE decoding table.
Instance Method Summary collapse
-
#decode(bitstream) ⇒ Integer
Decode next symbol from bitstream.
-
#decode_symbols(bitstream, count) ⇒ Array<Integer>
Decode multiple symbols.
-
#init_state(bitstream) ⇒ Object
Initialize state from bitstream.
-
#initialize(table) ⇒ Decoder
constructor
Initialize decoder with FSE table.
Constructor Details
#initialize(table) ⇒ Decoder
Initialize decoder with FSE table
214 215 216 217 |
# File 'lib/omnizip/algorithms/zstandard/fse/table.rb', line 214 def initialize(table) @table = table @state = 0 end |
Instance Attribute Details
#state ⇒ Integer (readonly)
Returns Current state.
209 210 211 |
# File 'lib/omnizip/algorithms/zstandard/fse/table.rb', line 209 def state @state end |
#table ⇒ Table (readonly)
Returns FSE decoding table.
206 207 208 |
# File 'lib/omnizip/algorithms/zstandard/fse/table.rb', line 206 def table @table end |
Instance Method Details
#decode(bitstream) ⇒ Integer
Decode next symbol from bitstream
230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 |
# File 'lib/omnizip/algorithms/zstandard/fse/table.rb', line 230 def decode(bitstream) entry = @table[@state] return 0 if entry.nil? symbol = entry.symbol # Read extra bits for next state if entry.num_bits.positive? extra = bitstream.read_bits(entry.num_bits) @state = entry.baseline + extra else @state = entry.baseline end # Mask state to table size @state &= (@table.size - 1) symbol end |
#decode_symbols(bitstream, count) ⇒ Array<Integer>
Decode multiple symbols
255 256 257 258 259 260 261 |
# File 'lib/omnizip/algorithms/zstandard/fse/table.rb', line 255 def decode_symbols(bitstream, count) symbols = [] count.times do symbols << decode(bitstream) end symbols end |
#init_state(bitstream) ⇒ Object
Initialize state from bitstream
222 223 224 |
# File 'lib/omnizip/algorithms/zstandard/fse/table.rb', line 222 def init_state(bitstream) @state = bitstream.read_bits(@table.accuracy_log) end |