Class: Omnizip::Parity::Models::CreatorPacket
- Inherits:
-
Packet
- Object
- Lutaml::Model::Serializable
- Packet
- Omnizip::Parity::Models::CreatorPacket
- Defined in:
- lib/omnizip/parity/models/creator_packet.rb
Overview
PAR2 Creator packet
Contains information about the tool that created the PAR2 file. This packet is optional but recommended for identification.
Body structure:
- creator_string (variable): Null-terminated string identifying the tool
Constant Summary collapse
- PACKET_TYPE =
Packet type identifier
"PAR 2.0\x00Creator\x00"
Constants inherited from Packet
Instance Attribute Summary
Attributes inherited from Packet
Instance Method Summary collapse
-
#build_body ⇒ String
Build body data from attributes.
-
#initialize(**attributes) ⇒ CreatorPacket
constructor
Initialize creator packet.
-
#parse_body ⇒ Object
Parse body data into attributes.
-
#tool_name ⇒ String
Get creator tool name.
-
#version ⇒ String?
Get creator version if available.
Methods inherited from Packet
#calculate_hash, #packet_type, read_from, #valid_hash?, #write_to
Constructor Details
#initialize(**attributes) ⇒ CreatorPacket
Initialize creator packet
23 24 25 26 |
# File 'lib/omnizip/parity/models/creator_packet.rb', line 23 def initialize(**attributes) super self.type = PACKET_TYPE end |
Instance Method Details
#build_body ⇒ String
Build body data from attributes
Constructs binary body data with null terminator
44 45 46 47 48 49 50 51 52 |
# File 'lib/omnizip/parity/models/creator_packet.rb', line 44 def build_body data = +"" # Write creator string (null-terminated) data << creator_string data << "\x00" self.body_data = data end |
#parse_body ⇒ Object
Parse body data into attributes
Body format:
- creator_string: null-terminated string
32 33 34 35 36 37 |
# File 'lib/omnizip/parity/models/creator_packet.rb', line 32 def parse_body return if body_data.nil? || body_data.empty? # Read creator string (null-terminated) self.creator_string = body_data.unpack1("Z*") end |
#tool_name ⇒ String
Get creator tool name
57 58 59 |
# File 'lib/omnizip/parity/models/creator_packet.rb', line 57 def tool_name creator_string.split.first || creator_string end |
#version ⇒ String?
Get creator version if available
64 65 66 67 |
# File 'lib/omnizip/parity/models/creator_packet.rb', line 64 def version parts = creator_string.split parts.size > 1 ? parts[1..].join(" ") : nil end |