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

Inherits:
Object
  • Object
show all
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

Instance Method Summary collapse

Constructor Details

#initialize(table) ⇒ Decoder

Initialize decoder with FSE table

Parameters:

  • table (Table)

    FSE decoding 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

#stateInteger (readonly)

Returns Current state.

Returns:

  • (Integer)

    Current state



209
210
211
# File 'lib/omnizip/algorithms/zstandard/fse/table.rb', line 209

def state
  @state
end

#tableTable (readonly)

Returns FSE decoding table.

Returns:

  • (Table)

    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

Parameters:

  • bitstream (BitStream)

    The bitstream to read from

Returns:

  • (Integer)

    Decoded symbol



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

Parameters:

  • bitstream (BitStream)

    The bitstream to read from

  • count (Integer)

    Number of symbols to decode

Returns:

  • (Array<Integer>)

    Decoded 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

Parameters:

  • bitstream (BitStream)

    The bitstream to read from



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