Class: Zrcon::Packet
- Inherits:
-
Object
- Object
- Zrcon::Packet
- Defined in:
- lib/zrcon/packet.rb
Instance Attribute Summary collapse
-
#data ⇒ Object
Returns the value of attribute data.
-
#id ⇒ Object
Returns the value of attribute id.
-
#type ⇒ Object
Returns the value of attribute type.
Class Method Summary collapse
Instance Method Summary collapse
- #encode ⇒ Object
-
#initialize(id: next_id, type: 2, data: "") ⇒ Packet
constructor
A new instance of Packet.
- #next_id ⇒ Object
Constructor Details
#initialize(id: next_id, type: 2, data: "") ⇒ Packet
Returns a new instance of Packet.
5 6 7 8 9 |
# File 'lib/zrcon/packet.rb', line 5 def initialize(id: next_id, type: 2, data: "") @id = id @type = type @data = data end |
Instance Attribute Details
#data ⇒ Object
Returns the value of attribute data.
3 4 5 |
# File 'lib/zrcon/packet.rb', line 3 def data @data end |
#id ⇒ Object
Returns the value of attribute id.
3 4 5 |
# File 'lib/zrcon/packet.rb', line 3 def id @id end |
#type ⇒ Object
Returns the value of attribute type.
3 4 5 |
# File 'lib/zrcon/packet.rb', line 3 def type @type end |
Class Method Details
.auth(password) ⇒ Object
20 21 22 |
# File 'lib/zrcon/packet.rb', line 20 def self.auth password new type: 3, data: password end |
.command(cmd) ⇒ Object
24 25 26 |
# File 'lib/zrcon/packet.rb', line 24 def self.command cmd new type: 2, data: cmd end |
.decode(raw) ⇒ Object
28 29 30 31 32 33 |
# File 'lib/zrcon/packet.rb', line 28 def self.decode raw raw = raw.to_s fields = raw.unpack("l<l<Z*x") Packet.new id: fields.shift, type: fields.shift, data: fields.shift end |
Instance Method Details
#encode ⇒ Object
16 17 18 |
# File 'lib/zrcon/packet.rb', line 16 def encode [10+data.length, id, type, data].pack("l<l<l<A#{data.length}xx") end |
#next_id ⇒ Object
11 12 13 14 |
# File 'lib/zrcon/packet.rb', line 11 def next_id @@id ||= -1 @@id += 1 end |