Class: Lib::BOOTP::Packet::TransactionID

Inherits:
Object
  • Object
show all
Extended by:
Forwardable
Includes:
Comparable
Defined in:
lib/lib/bootp/packet/transaction_id.rb

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(xid = nil) ⇒ TransactionID

Returns a new instance of TransactionID.



18
19
20
21
22
23
24
# File 'lib/lib/bootp/packet/transaction_id.rb', line 18

def initialize(xid = nil)
  xid = generate if xid.nil?
  unless xid >= 0 && xid <= 0xFFFFFFFF
    raise ArgumentError, "Not valid XID - #{xid} - should by 4 octet length"
  end
  @xid = xid
end

Class Method Details

.generateObject



30
31
32
# File 'lib/lib/bootp/packet/transaction_id.rb', line 30

def self.generate
  new Random.rand(0xFFFFFFFF)
end

.unpack(xid) ⇒ Object



47
48
49
# File 'lib/lib/bootp/packet/transaction_id.rb', line 47

def self.unpack(xid)
  new xid.unpack('N').first
end

Instance Method Details

#<=>(other) ⇒ Object



26
27
28
# File 'lib/lib/bootp/packet/transaction_id.rb', line 26

def <=>(other)
  self.to_i <=> other.to_i
end

#generate!Object



34
35
36
37
# File 'lib/lib/bootp/packet/transaction_id.rb', line 34

def generate!
  @xid = generate
  self
end

#packObject



43
44
45
# File 'lib/lib/bootp/packet/transaction_id.rb', line 43

def pack
  [@xid.to_i].pack('N')
end

#to_hexObject



39
40
41
# File 'lib/lib/bootp/packet/transaction_id.rb', line 39

def to_hex
  @xid.to_s(16)
end