Class: Omnizip::Algorithms::Zstandard::SequencesDecoder

Inherits:
Object
  • Object
show all
Includes:
Constants
Defined in:
lib/omnizip/algorithms/zstandard/sequences.rb

Overview

Sequences section decoder (RFC 8878 Section 3.1.1.3.2)

Decodes sequences of (literals_length, match_length, offset) which are then executed to produce the decompressed output.

Constant Summary

Constants included from Constants

Constants::BLOCK_HEADER_SIZE, Constants::BLOCK_MAX_SIZE, Constants::BLOCK_TYPE_COMPRESSED, Constants::BLOCK_TYPE_RAW, Constants::BLOCK_TYPE_RESERVED, Constants::BLOCK_TYPE_RLE, Constants::BUFFER_SIZE, Constants::DEFAULT_LEVEL, Constants::DEFAULT_REPEAT_OFFSETS, Constants::FSE_MAX_ACCURACY_LOG, Constants::FSE_MIN_ACCURACY_LOG, Constants::HUFFMAN_MAX_BITS, Constants::HUFFMAN_MAX_CODE_LENGTH, Constants::HUFFMAN_MAX_LOG, Constants::HUFFMAN_STANDARD_TABLE_SIZE, Constants::LITERALS_BLOCK_COMPRESSED, Constants::LITERALS_BLOCK_RAW, Constants::LITERALS_BLOCK_RLE, Constants::LITERALS_BLOCK_TREELESS, Constants::LITERALS_LENGTH_ACCURACY_LOG, Constants::LITERAL_LENGTH_TABLE, Constants::MAGIC_BYTES, Constants::MAGIC_NUMBER, Constants::MATCH_LENGTH_ACCURACY_LOG, Constants::MATCH_LENGTH_TABLE, Constants::MAX_LEVEL, Constants::MIN_LEVEL, Constants::MODE_FSE, Constants::MODE_PREDEFINED, Constants::MODE_REPEAT, Constants::MODE_RLE, Constants::OFFSET_ACCURACY_LOG, Constants::PREDEFINED_LL_DISTRIBUTION, Constants::PREDEFINED_ML_DISTRIBUTION, Constants::PREDEFINED_OFFSET_DISTRIBUTION, Constants::REPEAT_OFFSET_1, Constants::REPEAT_OFFSET_2, Constants::REPEAT_OFFSET_3, Constants::SKIPPABLE_MAGIC_BASE, Constants::SKIPPABLE_MAGIC_MASK, Constants::WINDOW_LOG_MAX, Constants::WINDOW_LOG_MIN

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(input, literals_size, previous_tables = {}) ⇒ SequencesDecoder

Initialize decoder

Parameters:

  • input (IO)

    Input stream

  • literals_size (Integer)

    Size of decoded literals

  • previous_tables (Hash) (defaults to: {})

    Previous FSE tables



53
54
55
56
57
58
59
# File 'lib/omnizip/algorithms/zstandard/sequences.rb', line 53

def initialize(input, literals_size, previous_tables = {})
  @input = input
  @literals_size = literals_size
  @previous_tables = previous_tables
  @sequences = []
  @fse_tables = {}
end

Instance Attribute Details

#sequencesArray<Hash> (readonly)

Returns Decoded sequences.

Returns:

  • (Array<Hash>)

    Decoded sequences



34
35
36
# File 'lib/omnizip/algorithms/zstandard/sequences.rb', line 34

def sequences
  @sequences
end

Class Method Details

.decode(input, literals_size, previous_tables = {}) ⇒ SequencesDecoder

Parse and decode sequences section

Parameters:

  • input (IO)

    Input stream positioned at sequences section

  • literals_size (Integer)

    Size of decoded literals

  • previous_tables (Hash) (defaults to: {})

    Previous FSE tables for REPEAT mode

Returns:



42
43
44
45
46
# File 'lib/omnizip/algorithms/zstandard/sequences.rb', line 42

def self.decode(input, literals_size, previous_tables = {})
  decoder = new(input, literals_size, previous_tables)
  decoder.decode_section
  decoder
end

Instance Method Details

#decode_sectionvoid

This method returns an undefined value.

Decode the sequences section



64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
# File 'lib/omnizip/algorithms/zstandard/sequences.rb', line 64

def decode_section
  # Read number of sequences
  num_sequences = read_sequence_count

  return if num_sequences.zero?

  # Read symbol compression modes
  modes = read_symbol_modes

  # Build FSE tables based on modes
  build_fse_tables(modes)

  # Decode sequences
  decode_sequences_internal(num_sequences)
end