Class: GG::PACKET

Inherits:
Object
  • Object
show all
Defined in:
lib/GRuby/GG_packets.rb

Overview

GG Packet class

Instance Method Summary collapse

Constructor Details

#initializePACKET

Returns a new instance of PACKET


7
8
9
# File 'lib/GRuby/GG_packets.rb', line 7

def initialize
  puts "++ #{self} created" if $DEBUG
end

Instance Method Details

#data=(data) ⇒ Object


44
45
46
47
# File 'lib/GRuby/GG_packets.rb', line 44

def data=(data)
  @data = data
  puts "++ #{self} recived data" if $DEBUG
end

#destroyObject


11
12
13
14
# File 'lib/GRuby/GG_packets.rb', line 11

def destroy
  puts "++ #{self} destroyed" if $DEBUG
  nil
end

#header=(data) ⇒ Object


16
17
18
19
20
# File 'lib/GRuby/GG_packets.rb', line 16

def header=(data)
  unpacked = data.unpack 'II'
  @type, @length = unpacked
  puts "++ #{self} recived header ... type:#{@type} length:#{@length}" if $DEBUG
end

#header_lengthObject


22
23
24
# File 'lib/GRuby/GG_packets.rb', line 22

def header_length
  8
end

#lengthObject


30
31
32
# File 'lib/GRuby/GG_packets.rb', line 30

def length
  @length
end

#pack(pattern) ⇒ Object


49
50
51
52
53
54
55
56
# File 'lib/GRuby/GG_packets.rb', line 49

def pack(pattern)
  begin
    puts "++ #{self} data packed" if $DEBUG
    packet.pack pattern
  rescue => e
    raise "packet pack ... #{e}"
  end
end

#typeObject


26
27
28
# File 'lib/GRuby/GG_packets.rb', line 26

def type
  @type
end

#type=(type) ⇒ Object


34
35
36
37
38
39
40
41
42
# File 'lib/GRuby/GG_packets.rb', line 34

def type=(type)
  begin
    self.extend	type
    puts "++ #{self} extend to #{type}" if $DEBUG
    fields @data if @data
  rescue => e
    raise "class extend ... #{e}"
  end
end