Class: Omnizip::Parity::ReedSolomonEncoder

Inherits:
Object
  • Object
show all
Defined in:
lib/omnizip/parity/reed_solomon_encoder.rb

Overview

Pure Reed-Solomon encoder for creating recovery blocks This is algorithm-only code with no I/O dependencies

Creates recovery blocks using Vandermonde matrix over GF(2^16):

Recovery[i] = sum(Input[j] * Base[j]^Exponent[i] for all j)

Class Method Summary collapse

Class Method Details

.encode(input_blocks, block_size, exponents) ⇒ Array<String>

Create recovery blocks from input blocks

Parameters:

  • input_blocks (Array<String>)

    Array of input block data (binary strings)

  • block_size (Integer)

    Size of each block in bytes (must be even for 16-bit processing)

  • exponents (Array<Integer>)

    Exponent for each recovery block (0-65535)

Returns:

  • (Array<String>)

    Array of recovery block data (binary strings)

Raises:

  • (ArgumentError)


17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
# File 'lib/omnizip/parity/reed_solomon_encoder.rb', line 17

def self.encode(input_blocks, block_size, exponents)
  if block_size.odd?
    raise ArgumentError,
          "Block size must be even for 16-bit processing"
  end
  raise ArgumentError, "No input blocks provided" if input_blocks.empty?
  raise ArgumentError, "No exponents provided" if exponents.empty?

  # Validate all input blocks have correct size
  input_blocks.each_with_index do |block, idx|
    unless block.bytesize == block_size
      raise ArgumentError,
            "Input block #{idx} has size #{block.bytesize}, expected #{block_size}"
    end
  end

  # Select base values using par2cmdline algorithm
  num_inputs = input_blocks.length
  bases = Par2cmdlineAlgorithm.compute_bases(num_inputs)

  # Create recovery blocks
  recovery_blocks = []
  exponents.each do |exponent|
    recovery_block = create_recovery_block(input_blocks, bases, exponent,
                                           block_size)
    recovery_blocks << recovery_block
  end

  recovery_blocks
end