Class: Omnizip::Algorithms::Zstandard::FSE::Decoder

Inherits:
Object
  • Object
show all
Defined in:
lib/omnizip/algorithms/zstandard/fse/table.rb

Overview

Stateful single-stream FSE decoder.

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(table) ⇒ Decoder

Returns a new instance of Decoder.

Parameters:



154
155
156
157
# File 'lib/omnizip/algorithms/zstandard/fse/table.rb', line 154

def initialize(table)
  @table = table
  @state = 0
end

Instance Attribute Details

#stateInteger (readonly)

Returns current state index.

Returns:

  • (Integer)

    current state index



151
152
153
# File 'lib/omnizip/algorithms/zstandard/fse/table.rb', line 151

def state
  @state
end

Instance Method Details

#current_symbolInteger

The symbol the current state decodes, without transitioning.

Returns:

  • (Integer)


181
182
183
# File 'lib/omnizip/algorithms/zstandard/fse/table.rb', line 181

def current_symbol
  @table[@state].symbol
end

#decode(bitstream) ⇒ Integer

Decode one symbol: read it from the current state, then transition.

Returns:

  • (Integer)

    symbol



168
169
170
171
172
173
174
175
176
# File 'lib/omnizip/algorithms/zstandard/fse/table.rb', line 168

def decode(bitstream)
  entry = @table[@state]
  @state = if entry.num_bits.positive?
             entry.baseline + bitstream.read_bits(entry.num_bits)
           else
             entry.baseline
           end
  entry.symbol
end

#init_state(bitstream) ⇒ Object

Initialize the state by reading accuracy_log bits.



160
161
162
# File 'lib/omnizip/algorithms/zstandard/fse/table.rb', line 160

def init_state(bitstream)
  @state = bitstream.read_bits(@table.accuracy_log)
end