Class: Omnizip::Parity::Models::RecoverySlicePacket

Inherits:
Packet
  • Object
show all
Defined in:
lib/omnizip/parity/models/recovery_slice_packet.rb

Overview

PAR2 Recovery Slice packet

Contains Reed-Solomon encoded recovery data for error correction.

Body structure:

  • exponent (4 bytes, L<): Recovery block exponent/index
  • recovery_data (variable): Reed-Solomon encoded block data

Constant Summary collapse

PACKET_TYPE =

Packet type identifier

"PAR 2.0\x00RecvSlic"

Constants inherited from Packet

Packet::PACKET_SIGNATURE

Instance Attribute Summary

Attributes inherited from Packet

#body_data

Instance Method Summary collapse

Methods inherited from Packet

#calculate_hash, #packet_type, read_from, #valid_hash?, #write_to

Constructor Details

#initialize(**attributes) ⇒ RecoverySlicePacket

Initialize recovery slice packet

Parameters:

  • attributes (Hash)

    Packet attributes



26
27
28
29
# File 'lib/omnizip/parity/models/recovery_slice_packet.rb', line 26

def initialize(**attributes)
  super
  self.type = PACKET_TYPE
end

Instance Method Details

#build_bodyString

Build body data from attributes

Constructs binary body data

Returns:

  • (String)

    Binary body data



55
56
57
58
59
60
61
62
63
64
65
# File 'lib/omnizip/parity/models/recovery_slice_packet.rb', line 55

def build_body
  data = +""

  # Write exponent (4 bytes, little-endian)
  data << [exponent].pack("L<")

  # Write recovery data
  data << recovery_data

  self.body_data = data
end

#data_sizeInteger

Get size of recovery data

Returns:

  • (Integer)

    Recovery data size in bytes



70
71
72
# File 'lib/omnizip/parity/models/recovery_slice_packet.rb', line 70

def data_size
  recovery_data.bytesize
end

#parse_bodyObject

Parse body data into attributes

Body format:

  • exponent: 4 bytes (L<)
  • recovery_data: remainder


36
37
38
39
40
41
42
43
44
45
46
47
48
# File 'lib/omnizip/parity/models/recovery_slice_packet.rb', line 36

def parse_body
  return if body_data.nil? || body_data.empty?
  return if body_data.bytesize < 4

  pos = 0

  # Read exponent (4 bytes, little-endian unsigned 32-bit)
  self.exponent = body_data[pos, 4].unpack1("L<")
  pos += 4

  # Read recovery data (remainder)
  self.recovery_data = body_data[pos..] || ""
end